aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/channel_stream.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/examples/channel_stream.rs b/examples/channel_stream.rs
index 38b0ee4..a278244 100644
--- a/examples/channel_stream.rs
+++ b/examples/channel_stream.rs
@@ -74,10 +74,18 @@ fn get_object_type(item: &serde_json::Value) -> &str {
.unwrap_or("unknown object")
}
-fn get_hashtags(item: &serde_json::Value) -> String {
+fn get_tags(item: &serde_json::Value) -> String {
match item["tags"] {
serde_json::Value::Array(ref v) => {
- v.iter().map(|t| get_str(&t["tag"])).collect::<Vec<_>>().join(", ")
+ v.iter().map(|t| {
+ let prefix = match get_str(&t["type"]) {
+ "hashtag" => "#",
+ "forum" => "!",
+ "mention" => "@",
+ _ => "",
+ };
+ format!("{}{}", prefix, get_str(&t["tag"]))
+ }).collect::<Vec<_>>().join(", ")
},
serde_json::Value::Null => {
String::new()
@@ -96,6 +104,6 @@ fn print_item(item: &serde_json::Value) {
println!("URL: {}", get_str(&author["url"]));
println!("Proto: {}", get_str(&author["network"]));
println!("Title: {}", get_str(&item["title"]));
- println!("Tags : {}", get_hashtags(&item));
+ println!("Tags : {}", get_tags(&item));
println!("Message:\n{}", get_str(&item["body"]));
}