In Rust you can add functions to other types with traits. This actually adds the like_a_cow function for all types that are printable, including strings. You have to use the trait though.
pubtraitLikeACow{fnlike_a_cow(&self)->String;}impl<T:std::fmt::Display>LikeACowforT{fnlike_a_cow(&self)->String{format!("Moo {} mooooo",&self)}}fnmain(){// need to `use LikeACow;` if used in other modules, but not here.lets="hello";println!("{}",s.like_a_cow());}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In Rust you can add functions to other types with traits. This actually adds the
like_a_cow
function for all types that are printable, including strings. You have touse
the trait though.