]> piware.de Git - learn-rust.git/blobdiff - concepts/src/main.rs
concepts: Dynamic trait objects
[learn-rust.git] / concepts / src / main.rs
index 94bdb960aa7e79b80d4ad22f082ab2822e6c1fbc..f9eafe95978b7bb802c7f1b8ffd3088cf2c19792 100644 (file)
@@ -247,6 +247,19 @@ 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.approve();
+    assert_eq!(text, post.content());
+}
+
 fn main() {
     test_strings();
     test_vectors();
@@ -256,4 +269,5 @@ fn main() {
     test_closures();
     test_iterators();
     test_threads();
+    test_dyn_traits();
 }