Skip to content

Add Model::try_set_option method#40

Merged
lovasoa merged 4 commits into
rust-or:mainfrom
alexdewar:try-set-option
Apr 29, 2026
Merged

Add Model::try_set_option method#40
lovasoa merged 4 commits into
rust-or:mainfrom
alexdewar:try-set-option

Conversation

@alexdewar

Copy link
Copy Markdown
Contributor

As discussed in #38, the Model::set_option method panics in the case of error, such as if an option does not exist or the value is invalid. While this is fine when you know you will only be setting valid options, it is not good if you are setting options dynamically, such as via user input. You can catch panics in Rust, but it's rather painful and it would be easier all round if we could just return an error in the usual way in this case.

Add a separate Model::try_set_option method which returns an error if it fails.

While I was at it, I tidied up another error message and changed things so that HighsOptionValue is re-exported as suggested in #39 (I was fiddling with this part of the code anyway).

Closes #38. Closes #39.

There are potential uses for it outside the crate, so let's re-export it. Closes rust-or#39.
@alexdewar

Copy link
Copy Markdown
Contributor Author

Oops, looks like clippy's complaining. I'll fix that up.

@alexdewar

Copy link
Copy Markdown
Contributor Author

Right, should be all good for review now.

@lovasoa lovasoa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@lovasoa lovasoa merged commit 093eb0b into rust-or:main Apr 29, 2026
2 checks passed
@alexdewar

Copy link
Copy Markdown
Contributor Author

Nw, thanks for looking at this 😄. Were you planning on making a new release soon btw? I'd like to use this feature in my downstream project. I can always use the git version of this crate for now if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose HighsOptionValue trait externally Add Model::try_set_option method

2 participants