diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-01-02 21:10:55 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-01-02 21:10:55 +0100 |
commit | 16a56f12cd2e66e10f8bb5e2c4026d3a7148e680 (patch) | |
tree | 913bd32a563b32302c2e14304460a3cbc9a88a39 /examples/zot | |
parent | 7f306445cb78d52f598eca1810dc2c5002e34a4a (diff) | |
download | rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.gz rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.bz2 rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.zip |
Cargo fmt
Diffstat (limited to 'examples/zot')
-rw-r--r-- | examples/zot/abconfig.rs | 2 | ||||
-rw-r--r-- | examples/zot/abook.rs | 15 | ||||
-rw-r--r-- | examples/zot/channel_stream.rs | 29 | ||||
-rw-r--r-- | examples/zot/group.rs | 23 | ||||
-rw-r--r-- | examples/zot/item.rs | 2 | ||||
-rw-r--r-- | examples/zot/network_stream.rs | 29 | ||||
-rw-r--r-- | examples/zot/xchan.rs | 2 |
7 files changed, 45 insertions, 57 deletions
diff --git a/examples/zot/abconfig.rs b/examples/zot/abconfig.rs index cc478ef..54d555c 100644 --- a/examples/zot/abconfig.rs +++ b/examples/zot/abconfig.rs @@ -21,7 +21,7 @@ pub fn fetch(client: &zotapi::Client) { match client.abconfig().fetch() { Ok(payload) => { println!("{}", payload); - }, + } Err(e) => { println!("{:?}", e); } diff --git a/examples/zot/abook.rs b/examples/zot/abook.rs index 7e91981..a16f68c 100644 --- a/examples/zot/abook.rs +++ b/examples/zot/abook.rs @@ -20,11 +20,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) { Ok(payload) => { if raw { println!("{}", &payload); - } - else { + } else { process(&payload); } - }, + } Err(e) => { println!("{:?}", e); } @@ -36,12 +35,12 @@ fn process(payload: &str) { match data { serde_json::Value::Array(v) => { for contact in v { - println!("{} ({}, {})", - contact["xchan_name"], - contact["xchan_addr"], - contact["xchan_network"]); + println!( + "{} ({}, {})", + contact["xchan_name"], contact["xchan_addr"], contact["xchan_network"] + ); } - }, + } _ => { println!("Unexpected data:\n{}", payload); } diff --git a/examples/zot/channel_stream.rs b/examples/zot/channel_stream.rs index a278244..b50f93f 100644 --- a/examples/zot/channel_stream.rs +++ b/examples/zot/channel_stream.rs @@ -25,11 +25,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) { Ok(payload) => { if raw { println!("{}", payload); - } - else { + } else { list(&payload); } - }, + } Err(e) => { println!("Error getting channel stream: {:?}", e); } @@ -43,10 +42,8 @@ fn list(payload: &str) { print_item(&item); println!("-----"); } - }, - Ok(_) => { - println!("Wrong type returned, expected an array.") - }, + } + Ok(_) => println!("Wrong type returned, expected an array."), Err(e) => { println!("Error: {}", e); } @@ -76,8 +73,9 @@ fn get_object_type(item: &serde_json::Value) -> &str { fn get_tags(item: &serde_json::Value) -> String { match item["tags"] { - serde_json::Value::Array(ref v) => { - v.iter().map(|t| { + serde_json::Value::Array(ref v) => v + .iter() + .map(|t| { let prefix = match get_str(&t["type"]) { "hashtag" => "#", "forum" => "!", @@ -85,14 +83,11 @@ fn get_tags(item: &serde_json::Value) -> String { _ => "", }; format!("{}{}", prefix, get_str(&t["tag"])) - }).collect::<Vec<_>>().join(", ") - }, - serde_json::Value::Null => { - String::new() - }, - _ => { - String::from("invalid tags, expected array...") - } + }) + .collect::<Vec<_>>() + .join(", "), + serde_json::Value::Null => String::new(), + _ => String::from("invalid tags, expected array..."), } } diff --git a/examples/zot/group.rs b/examples/zot/group.rs index e02fb13..9264cdc 100644 --- a/examples/zot/group.rs +++ b/examples/zot/group.rs @@ -15,11 +15,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -use serde_json::{Value, from_str}; +use serde_json::{from_str, Value}; pub fn list(data: &str) { if let Ok(Value::Array(groups)) = from_str(&data) { - println!("Id | Group name | uid | flags | hash"); println!("----+------------------+-----+-------+-------------------------"); @@ -38,34 +37,34 @@ pub fn list(data: &str) { } } - print!("{:>3} | {:16} | {:>3} | {:5} | {}\n", + print!( + "{:>3} | {:16} | {:>3} | {:5} | {}\n", group["id"].as_u64().unwrap(), group["gname"].as_str().unwrap(), group["uid"].as_u64().unwrap(), flags, - group["hash"].as_str().unwrap()); + group["hash"].as_str().unwrap() + ); } - } - else { + } else { eprintln!("Invalid data"); } } - pub fn list_members(data: &str) { if let Ok(Value::Array(members)) = from_str(&data) { - println!("Id | Name | Address"); println!("----+-------------------------------+------------------------"); for member in members { - println!("{:>3} | {:29} | {}", + println!( + "{:>3} | {:29} | {}", member["id"].as_u64().unwrap(), member["xchan_name"].as_str().unwrap(), - member["xchan_addr"].as_str().unwrap()); + member["xchan_addr"].as_str().unwrap() + ); } - } - else { + } else { eprintln!("Invalid data"); } } diff --git a/examples/zot/item.rs b/examples/zot/item.rs index e848af2..dec6c8d 100644 --- a/examples/zot/item.rs +++ b/examples/zot/item.rs @@ -39,7 +39,7 @@ pub fn post(client: &zotapi::Client, args: &ArgMatches) { match msg.create() { Ok(payload) => { println!("Raw payload: {}", payload); - }, + } Err(e) => { println!("Error posting message: {:?}", e); } diff --git a/examples/zot/network_stream.rs b/examples/zot/network_stream.rs index de3b12f..6dc1a0c 100644 --- a/examples/zot/network_stream.rs +++ b/examples/zot/network_stream.rs @@ -25,11 +25,10 @@ pub fn fetch(client: &zotapi::Client, raw: bool) { Ok(payload) => { if raw { println!("{}", payload); - } - else { + } else { list(&payload); } - }, + } Err(e) => { println!("Error getting channel stream: {:?}", e); } @@ -43,10 +42,8 @@ fn list(payload: &str) { print_item(&item); println!("-----"); } - }, - Ok(_) => { - println!("Wrong type returned, expected an array.") - }, + } + Ok(_) => println!("Wrong type returned, expected an array."), Err(e) => { println!("Error: {}", e); } @@ -76,8 +73,9 @@ fn get_object_type(item: &serde_json::Value) -> &str { fn get_tags(item: &serde_json::Value) -> String { match item["tags"] { - serde_json::Value::Array(ref v) => { - v.iter().map(|t| { + serde_json::Value::Array(ref v) => v + .iter() + .map(|t| { let prefix = match get_str(&t["type"]) { "hashtag" => "#", "forum" => "!", @@ -85,14 +83,11 @@ fn get_tags(item: &serde_json::Value) -> String { _ => "", }; format!("{}{}", prefix, get_str(&t["tag"])) - }).collect::<Vec<_>>().join(", ") - }, - serde_json::Value::Null => { - String::new() - }, - _ => { - String::from("invalid tags, expected array...") - } + }) + .collect::<Vec<_>>() + .join(", "), + serde_json::Value::Null => String::new(), + _ => String::from("invalid tags, expected array..."), } } diff --git a/examples/zot/xchan.rs b/examples/zot/xchan.rs index d37328d..d2d73d0 100644 --- a/examples/zot/xchan.rs +++ b/examples/zot/xchan.rs @@ -33,7 +33,7 @@ pub fn fetch(client: &zotapi::Client, _raw: bool, t: Type, id: &str) { match res { Ok(payload) => { println!("{}", payload); - }, + } Err(e) => { println!("{:?}", e); } |