From 8d20318f22fa0344fa8804e15263b7736c6eff15 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Mon, 8 Oct 2018 10:14:24 +0200 Subject: Differ between different type of tags in channel_stream example. --- examples/channel_stream.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'examples/channel_stream.rs') 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::>().join(", ") + v.iter().map(|t| { + let prefix = match get_str(&t["type"]) { + "hashtag" => "#", + "forum" => "!", + "mention" => "@", + _ => "", + }; + format!("{}{}", prefix, get_str(&t["tag"])) + }).collect::>().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"])); } -- cgit v1.2.3