rust-book/blog/src/lib.rs

45 lines
700 B
Rust
Raw Normal View History

2019-02-06 14:54:11 -05:00
pub struct Post {
content: String,
}
pub struct DraftPost {
2019-02-06 14:54:11 -05:00
content: String,
}
impl Post {
pub fn new() -> DraftPost {
DraftPost {
2019-02-06 14:54:11 -05:00
content: String::new(),
}
}
pub fn content(&self) -> &str {
&self.content
2019-02-06 14:54:11 -05:00
}
}
2019-02-06 14:54:11 -05:00
impl DraftPost {
pub fn add_text(&mut self, text: &str) {
self.content.push_str(text);
2019-02-06 14:54:11 -05:00
}
pub fn request_review(self) -> PendingReviewPost {
PendingReviewPost {
content: self.content,
2019-02-06 14:54:11 -05:00
}
}
}
pub struct PendingReviewPost {
content: String,
2019-02-06 14:54:11 -05:00
}
impl PendingReviewPost {
pub fn approve(self) -> Post {
Post {
content: self.content,
}
2019-02-06 14:54:11 -05:00
}
}