역참조1 [Rust] Deref(역참조) 예제 (36일차) use std::ops::Deref; struct MyBox(T); impl MyBox { fn new(x: T) -> MyBox { MyBox(x) } } impl Deref for MyBox { type Target = T; fn deref(&self) -> &T { &self.0 } } fn hello(name: &str) { println!("Hello, {}!", name); } fn main() { let m = MyBox::new(String::from("Rust")); hello(&m); } https://rinthel.github.io/rust-lang-book-ko/ch15-02-deref.html 2023. 1. 19. 이전 1 다음