rust-or/good_lp

Add const to determine at compile-time what default_solver resolves to

Closed this issue · 1 comments

Motivation: my application uses good_lp, and mirrors the structure you have here of using features to enable/disable various solver backends. I would like to be able to print out which solver is being used.

There's some reasonably complex logic in

good_lp/src/lib.rs

Lines 73 to 110 in f7483e2

#[cfg(feature = "coin_cbc")]
/// When the "coin_cbc" cargo feature is present, it is used as the default solver
pub use solvers::coin_cbc::coin_cbc as default_solver;
#[cfg(feature = "highs")]
#[cfg_attr(docsrs, doc(cfg(feature = "highs")))]
pub use solvers::highs::highs;
#[cfg(not(any(feature = "coin_cbc", feature = "minilp", feature = "lpsolve")))]
#[cfg(feature = "highs")]
/// When the "highs" cargo feature is present, highs is used as the default solver
pub use solvers::highs::highs as default_solver;
#[cfg(feature = "lp-solvers")]
#[cfg_attr(docsrs, doc(cfg(feature = "lp-solvers")))]
pub use solvers::lp_solvers::LpSolver;
#[cfg(feature = "lpsolve")]
#[cfg_attr(docsrs, doc(cfg(feature = "lpsolve")))]
pub use solvers::lpsolve::lp_solve;
#[cfg(not(any(feature = "coin_cbc", feature = "minilp")))]
#[cfg(feature = "lpsolve")]
/// When the "lpsolve" cargo feature is present, lpsolve is used as the default solver
pub use solvers::lpsolve::lp_solve as default_solver;
#[cfg(feature = "minilp")]
#[cfg_attr(docsrs, doc(cfg(feature = "minilp")))]
pub use solvers::minilp::minilp;
#[cfg(not(feature = "coin_cbc"))]
#[cfg(feature = "minilp")]
/// When the "coin_cbc" cargo feature is absent, minilp is used as the default solver
pub use solvers::minilp::minilp as default_solver;
#[cfg(feature = "scip")]
#[cfg_attr(docsrs, doc(cfg(feature = "highs")))]
pub use solvers::scip::scip;
#[cfg(not(any(
feature = "coin_cbc",
feature = "minilp",
feature = "lpsolve",
feature = "highs"
)))]
#[cfg(feature = "scip")]
pub use solvers::scip::scip as default_solver;
to determine which solver is the default which I'd rather not copy. I think the cleanest solution would be to add something like pub const SOLVER_NAME: &str = "cbc" in src/solvers/coin_cbc.rs etc. and reexport it.

That would be a nice and useful feature indeed ! Do you want to open a small PR ? I can help if you have any question !