X-Git-Url: https://piware.de/gitweb/?p=learn-rust.git;a=blobdiff_plain;f=concepts%2Fsrc%2Fmain.rs;h=3e9bbbd0cd042234615d20dd563baf6278258464;hp=94bdb960aa7e79b80d4ad22f082ab2822e6c1fbc;hb=6cf2fd87f634bb24ca0ab801a8ba3fbfff1ac418;hpb=89ba5f70f2de2cf038b2abb701a3d257c6b965d8 diff --git a/concepts/src/main.rs b/concepts/src/main.rs index 94bdb96..3e9bbbd 100644 --- a/concepts/src/main.rs +++ b/concepts/src/main.rs @@ -247,6 +247,25 @@ fn test_threads() { println!("counter: {}", *counter.lock().unwrap()); } +fn test_dyn_traits() { + let text = "I ate a salad for lunch today"; + let mut post = Post::new(); + post.add_text(text); + assert_eq!("", post.content()); + + post.request_review(); + assert_eq!("", post.content()); + + post.reject(); + assert_eq!("", post.content()); + + post.request_review(); + assert_eq!("", post.content()); + + post.approve(); + assert_eq!(text, post.content()); +} + fn main() { test_strings(); test_vectors(); @@ -256,4 +275,5 @@ fn main() { test_closures(); test_iterators(); test_threads(); + test_dyn_traits(); }