diff --git a/state_pattern_oop/src/main.rs b/state_pattern_oop/src/main.rs index b8dfa55..dc904a1 100644 --- a/state_pattern_oop/src/main.rs +++ b/state_pattern_oop/src/main.rs @@ -35,6 +35,7 @@ impl Post { trait State { fn request_review(self: Box) -> Box; fn approve(self: Box) -> Box; + fn reject(self: Box) -> Box; fn content<'a>(&self, _post: &'a Post) -> &'a str { "" @@ -51,6 +52,10 @@ impl State for Draft { fn approve(self: Box) -> Box { self } + + fn reject(self: Box) -> Box { + self + } } struct PendingReview {} @@ -63,6 +68,10 @@ impl State for PendingReview { fn approve(self: Box) -> Box { Box::new(Published {}) } + + fn reject(self: Box) -> Box { + Box::new(Draft {}) + } } struct Published {} @@ -79,6 +88,10 @@ impl State for Published { fn content<'a>(&self, post: &'a Post) -> &'a str { &post.content } + + fn reject(self: Box) -> Box { + self + } } fn main() {