pub fn approve(&mut self) {
self.state = self.state.approve();
}
+
+ pub fn reject(&mut self) {
+ self.state = self.state.reject();
+ }
}
trait State {
fn request_review(&self) -> Box<dyn State>;
fn approve(&self) -> Box<dyn State>;
+ fn reject(&self) -> Box<dyn State>;
#[allow(unused_variables)]
fn content<'a>(&self, post: &'a Post) -> &'a str {
// don't change state
Box::new(Self {})
}
+
+ fn reject(&self) -> Box<dyn State> {
+ Box::new(Self {})
+ }
}
struct PendingReview {}
fn approve(&self) -> Box<dyn State> {
Box::new(Published {})
}
+
+ fn reject(&self) -> Box<dyn State> {
+ Box::new(Draft {})
+ }
}
struct Published {}
Box::new(Published {})
}
+ fn reject(&self) -> Box<dyn State> {
+ Box::new(Self {})
+ }
+
fn content<'a>(&self, post: &'a Post) -> &'a str {
&post.content
}