함수 인자 타입이 &str일 때, &String 타입을 받을 수 있잖아?
근데 이거 정확한 이유가 뭐임?
러스트의 deref coercion에 의해서 &&String이여도 &String으로 변환된다는 것도 알겠고
&str은 heap말고 read-only memory에 있는 것도 알고,
String은 length와 capacity를 가지며 문자열에 대한 포인터를 가진다는 것도 알고 뭐 다 알겠는데
결정적으로 &str 대신 &String을 쓸 수 있는 이유를 모르겠음.
이게 뭐 어떤 trait이 String에 구현되어있는건가?? 자세히 설명가능한분?
Deref trait을 구현했어도 Deref trait은 * 연산자에 대해서 바꿔주는거 아님?
&String같은경우 *가 아니라 &연산자가 들어갔는데 이 부분에서 이해가 안감
https://doc.rust-lang.org/book/ch15-02-deref.html#treating-a-type-like-a-reference-by-implementing-the-deref-trait
https://doc.rust-lang.org/book/ch08-02-strings.html?storing-utf-8-encoded-text-with-strings#slicing-strings
https://doc.rust-lang.org/reference/type-coercions.html#coercion-types
&T or &mut T to &U if T implements Deref.
일단 deref coercion에 대한 이해가 부족하다
If you have a type U, and it implements Deref[Target=T], values of &U will automatically coerce to a &T
String은 str을 Target으로 갖는 Deref 트레잇을 구현한다는걸 생각해야함