# hamcrest-rust **Repository Path**: mirrors_aschoerk/hamcrest-rust ## Basic Information - **Project Name**: hamcrest-rust - **Description**: A port of Hamcrest to rust - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-11-23 - **Last Updated**: 2026-03-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hamcrest A port of [Hamcrest](http://hamcrest.org/) to [Rust](http://rust-lang.org). ## Installing To use Hamcrest, add this to your `Cargo.toml`: ``` [dev-dependencies.hamcrest] git = "https://github.com/carllerche/hamcrest-rust.git" ``` And this to your crate root: ```{rust} #[cfg(test)] extern crate hamcrest; ``` After a quick `cargo build`, you should be good to go! ## Usage Hamcrest supports a number of matchers. You'll have to `use` them just like any other Rust library. ### equal\_to ```{rust} // Successful match assert_that(&1, is(equal_to(&1i))); // Unsuccessful match let res = task::try(proc() { assert_that(&2, is(equal_to(&1i))); }); assert!(res.is_err()); ``` ### close\_to ```{rust} assert_that(1e-40f32, is(close_to(0.0, 0.01))); assert_that(1e-40f32, is_not(close_to(0.0, 0.000001))); ``` ### existing\_{file,path,dir} ```{rust} assert_that(&path, is(existing_path())); assert_that(&path, is(existing_file())); assert_that(&path, is_not(existing_dir())); ``` ### none ```{rust} assert_that(None, is(none::())); assert_that(Some(1), is_not(none::())); ``` ### contains and contains\_exactly ```{rust} assert_that(&vec!(1i, 2, 3), contains(vec!(1i, 2))); assert_that(&vec!(1i, 2, 3), not(contains(vec!(4i)))); assert_that(&vec!(1i, 2, 3), contains(vec!(1i, 2, 3)).exactly()); assert_that(&vec!(1i, 2, 3), not(contains(vec!(1i, 2)).exactly())); ```