mirror of
https://github.com/gnu4cn/rust-lang-zh_CN.git
synced 2026-08-22 14:13:28 +08:00
Update Ch15
This commit is contained in:
@@ -1,3 +1,25 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use std::ops::Deref;
|
||||
|
||||
struct MyBox<T>(T);
|
||||
|
||||
impl<T> MyBox<T> {
|
||||
fn new(x: T) -> MyBox<T> {
|
||||
MyBox(x)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for MyBox<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let boxed_string = MyBox::new(String::from("装箱的字符串"));
|
||||
|
||||
let x = 5;
|
||||
let y = &x;
|
||||
println! ("{}, {}", *boxed_string, *y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user