Bisector
Overview
A flexible, stateless implementation of the bisection method.
Flexibility is achieved by giving the user of this crate control over the input and output types. That is, this implementation is not limited to numeric types. In addition, the implementation is stateless. The Bisector struct on which the bisect methods are implemented does not hold internal mutable state of the last step. This gives the user the option to re-execute a step, or really perform any step in the order the user desires (although incremental steps may be most logical still 😅).
The lack of internal mutable state also allows the implementation to take a shared reference (&self), instead of an exclusive
reference (&mut self), which is convenient when dealing with ownership in many cases, and was the original reason
behind this crate.
Install
Cargo
- Last published version on crates.io (recommended):
Add the bisector crate to list of dependencies in your Cargo manifest (Cargo.toml):
[]
= "*" # replace `*` with latest version
- Last development version on GitHub:
Add the bisector crate to list of dependencies in your Cargo manifest (Cargo.toml):
[]
= { = "https://github.com/foresterre/bisector.git" }
MSRV
The Minimal Supported Rust Version was determined with cargo-msrv, and
is verified on the during CI runs. The table below lists the MSRV for the current and historical versions of bisector.
bisector version |
MSRV |
|---|---|
| 0.1.0 | N/A |
| 0.2.0 | N/A |
| 0.3.0 | 1.37 |
| 0.4.0 | 1.37 |
Examples
Example 1
Example 2
// NB: output held by ConvergeTo does *not* need to be of the same type as
// the value. In this example, it just happens to be the case.
Example: bisect in cargo msrv
A more contrived example can be found in cargo msrv.
NB: Linked revision was implemented before Bisector::try_bisect was added. To cover a fallible case in the convergence function, you may want to use Bisector::try_bisect over Bisector::bisect.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.