Hi Friends,
I'm fairly new to Rust and am having the following issue. The codebase I work in liberally uses the From<Thing> for OtherThing
trait. Invocations of this trait look like some_thing.into()
. My problem is that its difficult to tell where this is called. For example, lets say I have the following definition:
struct Person {
first_name: String,
last_name: String
}
impl From<MyStruct> for String {
fn from(m: MyStruct) -> String {
format!("{},{}", m.first_name, m.last_name)
}
}
pub fn do_thing(s: String) {
println!("S is: {}", s);
}
pub fn main() {
let p = Person{
first_name: String::from("dave"),
last_name: String::from("someone")
};
do_thing(p.into());
}
Trying to find invocations of this trait via calls to into is difficult. I have to find all variables of type MyStruct, that are being implicitly cast to String. Is there a better way to do this? If not is there a better way to invoke this trait to make it easier to search?
Thank you!