Why some type like Box can inherit its generic's methods? For example,
Box
let box = Box::new(String::from("ABCD")); box.push_str("EFG");
Box contains a String can be used as a String. Arc type can also do that.
String
Arc
What is this? Is there any syntax to do this?
It's because Box<T> implements the Deref trait, which allows the compiler to essentially implicitly convert &Box<T> to &T. See the chapter about Deref in TRPL.
Box<T>
Deref
&Box<T>
&T
Thanks very much!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.