trpl-zh-cn/listings/ch17-oop/listing-17-12/src/lib.rs

20 lines
288 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
pub struct Post {
state: Option<Box<dyn State>>,
content: String,
}
impl Post {
pub fn new() -> Post {
Post {
state: Some(Box::new(Draft {})),
content: String::new(),
}
}
}
trait State {}
struct Draft {}
impl State for Draft {}