From 69a6436139bee7332a72c37e1ddba4f8993589d2 Mon Sep 17 00:00:00 2001 From: laurens Date: Sun, 11 Oct 2020 15:31:27 +0200 Subject: [PATCH] state_pattern_oop: add reject method --- state_pattern_oop/src/main.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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() {