diff --git a/2_idioms/2_4_generic_in_type_out/README.md b/2_idioms/2_4_generic_in_type_out/README.md index 3280a9dd..f85d9179 100644 --- a/2_idioms/2_4_generic_in_type_out/README.md +++ b/2_idioms/2_4_generic_in_type_out/README.md @@ -13,6 +13,8 @@ The common and obvious rules in [Rust] when choosing type for an input parameter Let's illustrate it with the following trivial examples: ```rust +use derive_more::{AsRef, AsMut}; + // Read-only access is enough here. pub fn just_print_stringy(v: &str) { println!("{}", v) @@ -25,6 +27,8 @@ pub fn add_hi(v: &mut String) { #[derive(AsMut, AsRef)] pub struct Nickname(String); + + impl Nickname { // We want to own `nickname` inside `Nickname` value. pub fn new(nickname: String) -> Self { @@ -41,19 +45,25 @@ just_print_stringy(nickname.as_ref()); The most standard way to improve ergonomics here is to __hide type conversions under-the-hood by abstracting over input types__ in our APIs: ```rust -pub fn just_print_stringy>(v: S) { +use derive_more::{AsRef, AsMut}; + +pub fn just_print_stringy>(v: S) { println!("{}", v.as_ref()) } -pub fn add_hi>(v: S) { +pub fn add_hi>(mut v: S) { v.as_mut().push_str(" Hi") } -impl Nickname { +#[derive(AsMut, AsRef)] +pub struct Nickname(String); + +impl Nickname { pub fn new>(nickname: S) -> Self { Self(nickname.into()) } } + ``` And now our API is pleasant to use: ```rust diff --git a/3_ecosystem/3_1_testing/README.md b/3_ecosystem/3_1_testing/README.md index 22d60a02..f5a7d603 100644 --- a/3_ecosystem/3_1_testing/README.md +++ b/3_ecosystem/3_1_testing/README.md @@ -122,6 +122,16 @@ For better understanding and familiarity with [fuzzing][31] in [Rust], read thro - [Integrated tests are scam (J.B. Rainsberg)][61] - [nextest][62] +## CLI Testing +- [assert_cmd](https://crates.io/crates/assert_cmd) - Easy command initialization and assertions. +- [assert_fs](https://crates.io/crates/assert_fs) - Filesystem fixtures and assertions for testing. +- [predicates](https://crates.io/crates/predicates) - Composable first-order predicate functions. +- [rexpect](https://crates.io/crates/rexpect) - For interactive CLI testing. +- [CLI testing](https://rust-cli.github.io/book/tutorial/testing.html) +- [example with rexpect](https://www.rustadventure.dev/building-a-digital-garden-cli/clap-v4/testing-interactive-clis-with-rexpect) +- [one more example](https://out-of-cheese-error.netlify.app/the-way) + + ## Task