Tricks

Allow everything what can be a str reference

 

fn do_something<S: AsRef<str>>(input: S) {
  let input_str = input.as_ref();
  println!("This is a &str: {}", input_str);
}

do_something("Hello World");
do_something("Hello World".to_string());

 


Revision #1
Created 2026-03-11 15:01:38 UTC by Matthias
Updated 2026-03-11 15:03:29 UTC by Matthias