From 525f21c871f4947196dc8348019d941e84bf6e3c Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 15:07:12 -0700 Subject: make cargo fmt succeed by default --- rust/fatcat-api/examples/client.rs | 245 ++++---------------------- rust/fatcat-api/examples/server.rs | 16 +- rust/fatcat-api/examples/server_lib/server.rs | 229 +++++------------------- 3 files changed, 74 insertions(+), 416 deletions(-) (limited to 'rust/fatcat-api/examples') diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs index bd43e7cc..8c1ec930 100644 --- a/rust/fatcat-api/examples/client.rs +++ b/rust/fatcat-api/examples/client.rs @@ -11,13 +11,9 @@ extern crate uuid; use clap::{App, Arg}; #[allow(unused_imports)] -use fatcat::{ApiError, ApiNoContext, ContainerIdGetResponse, ContainerLookupGetResponse, - ContainerPostResponse, ContextWrapperExt, CreatorIdGetResponse, - CreatorLookupGetResponse, CreatorPostResponse, EditgroupIdAcceptPostResponse, - EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, - EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, - FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, - ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; +use fatcat::{ApiError, ApiNoContext, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, ContextWrapperExt, CreatorIdGetResponse, CreatorLookupGetResponse, + CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, + FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; #[allow(unused_imports)] use futures::{future, stream, Future, Stream}; @@ -50,25 +46,9 @@ fn main() { .required(true) .index(1), ) - .arg( - Arg::with_name("https") - .long("https") - .help("Whether to use HTTPS or not"), - ) - .arg( - Arg::with_name("host") - .long("host") - .takes_value(true) - .default_value("api.fatcat.wiki") - .help("Hostname to contact"), - ) - .arg( - Arg::with_name("port") - .long("port") - .takes_value(true) - .default_value("8080") - .help("Port to contact"), - ) + .arg(Arg::with_name("https").long("https").help("Whether to use HTTPS or not")) + .arg(Arg::with_name("host").long("host").takes_value(true).default_value("api.fatcat.wiki").help("Hostname to contact")) + .arg(Arg::with_name("port").long("port").takes_value(true).default_value("8080").help("Port to contact")) .get_matches(); let is_https = matches.is_present("https"); @@ -80,272 +60,109 @@ fn main() { ); let client = if is_https { // Using Simple HTTPS - fatcat::Client::try_new_https(&base_url, "examples/ca.pem") - .expect("Failed to create HTTPS client") + fatcat::Client::try_new_https(&base_url, "examples/ca.pem").expect("Failed to create HTTPS client") } else { // Using HTTP fatcat::Client::try_new_http(&base_url).expect("Failed to create HTTP client") }; // Using a non-default `Context` is not required; this is just an example! - let client = client.with_context(fatcat::Context::new_with_span_id( - self::uuid::Uuid::new_v4().to_string(), - )); + let client = client.with_context(fatcat::Context::new_with_span_id(self::uuid::Uuid::new_v4().to_string())); match matches.value_of("operation") { Some("ContainerIdGet") => { let result = client.container_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("ContainerLookupGet") => { - let result = client - .container_lookup_get("issn_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + let result = client.container_lookup_get("issn_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("ContainerPost") => { let result = client.container_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("CreatorIdGet") => { let result = client.creator_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("CreatorLookupGet") => { - let result = client - .creator_lookup_get("orcid_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + let result = client.creator_lookup_get("orcid_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("CreatorPost") => { let result = client.creator_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("EditgroupIdAcceptPost") => { let result = client.editgroup_id_accept_post(56).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("EditgroupIdGet") => { let result = client.editgroup_id_get(56).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("EditgroupPost") => { let result = client.editgroup_post().wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("EditorUsernameChangelogGet") => { - let result = client - .editor_username_changelog_get("username_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + let result = client.editor_username_changelog_get("username_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("EditorUsernameGet") => { - let result = client - .editor_username_get("username_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + let result = client.editor_username_get("username_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("FileIdGet") => { let result = client.file_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("FileLookupGet") => { let result = client.file_lookup_get("sha1_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("FilePost") => { let result = client.file_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("ReleaseIdGet") => { let result = client.release_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("ReleaseLookupGet") => { let result = client.release_lookup_get("doi_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("ReleasePost") => { let result = client.release_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("WorkIdGet") => { let result = client.work_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } Some("WorkPost") => { let result = client.work_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from(""))); } _ => panic!("Invalid operation provided"), diff --git a/rust/fatcat-api/examples/server.rs b/rust/fatcat-api/examples/server.rs index e97d69ca..612ec4b2 100644 --- a/rust/fatcat-api/examples/server.rs +++ b/rust/fatcat-api/examples/server.rs @@ -43,13 +43,7 @@ fn ssl() -> Result { /// Create custom server, wire it to the autogenerated router, /// and pass it to the web server. fn main() { - let matches = App::new("server") - .arg( - Arg::with_name("https") - .long("https") - .help("Whether to use HTTPS or not"), - ) - .get_matches(); + let matches = App::new("server").arg(Arg::with_name("https").long("https").help("Whether to use HTTPS or not")).get_matches(); let server = server_lib::server().unwrap(); let router = fatcat::router(server); @@ -62,13 +56,9 @@ fn main() { if matches.is_present("https") { // Using Simple HTTPS - Iron::new(chain) - .https("localhost:8080", ssl().expect("Failed to load SSL keys")) - .expect("Failed to start HTTPS server"); + Iron::new(chain).https("localhost:8080", ssl().expect("Failed to load SSL keys")).expect("Failed to start HTTPS server"); } else { // Using HTTP - Iron::new(chain) - .http("localhost:8080") - .expect("Failed to start HTTP server"); + Iron::new(chain).http("localhost:8080").expect("Failed to start HTTP server"); } } diff --git a/rust/fatcat-api/examples/server_lib/server.rs b/rust/fatcat-api/examples/server_lib/server.rs index ec915786..fc0e5174 100644 --- a/rust/fatcat-api/examples/server_lib/server.rs +++ b/rust/fatcat-api/examples/server_lib/server.rs @@ -10,146 +10,69 @@ use std::collections::HashMap; use swagger; use fatcat::models; -use fatcat::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse, - ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse, - CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, - EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, - FileIdGetResponse, FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, - ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; +use fatcat::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse, + EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, + FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; #[derive(Copy, Clone)] pub struct Server; impl Api for Server { - fn container_id_get( - &self, - id: String, - context: &Context, - ) -> Box + Send> { + fn container_id_get(&self, id: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "container_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("container_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn container_lookup_get( - &self, - issn: String, - context: &Context, - ) -> Box + Send> { + fn container_lookup_get(&self, issn: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "container_lookup_get(\"{}\") - X-Span-ID: {:?}", - issn, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("container_lookup_get(\"{}\") - X-Span-ID: {:?}", issn, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn container_post( - &self, - body: Option, - context: &Context, - ) -> Box + Send> { + fn container_post(&self, body: Option, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "container_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("container_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_id_get( - &self, - id: String, - context: &Context, - ) -> Box + Send> { + fn creator_id_get(&self, id: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "creator_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("creator_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_lookup_get( - &self, - orcid: String, - context: &Context, - ) -> Box + Send> { + fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "creator_lookup_get(\"{}\") - X-Span-ID: {:?}", - orcid, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("creator_lookup_get(\"{}\") - X-Span-ID: {:?}", orcid, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_post( - &self, - body: Option, - context: &Context, - ) -> Box + Send> { + fn creator_post(&self, body: Option, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "creator_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("creator_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_id_accept_post( - &self, - id: i32, - context: &Context, - ) -> Box + Send> { + fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "editgroup_id_accept_post({}) - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("editgroup_id_accept_post({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_id_get( - &self, - id: i32, - context: &Context, - ) -> Box + Send> { + fn editgroup_id_get(&self, id: i32, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "editgroup_id_get({}) - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("editgroup_id_get({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_post( - &self, - context: &Context, - ) -> Box + Send> { + fn editgroup_post(&self, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "editgroup_post() - X-Span-ID: {:?}", - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("editgroup_post() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editor_username_changelog_get( - &self, - username: String, - context: &Context, - ) -> Box + Send> { + fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box + Send> { let context = context.clone(); println!( "editor_username_changelog_get(\"{}\") - X-Span-ID: {:?}", @@ -159,129 +82,57 @@ impl Api for Server { Box::new(futures::failed("Generic failure".into())) } - fn editor_username_get( - &self, - username: String, - context: &Context, - ) -> Box + Send> { + fn editor_username_get(&self, username: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "editor_username_get(\"{}\") - X-Span-ID: {:?}", - username, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("editor_username_get(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_id_get( - &self, - id: String, - context: &Context, - ) -> Box + Send> { + fn file_id_get(&self, id: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "file_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("file_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_lookup_get( - &self, - sha1: String, - context: &Context, - ) -> Box + Send> { + fn file_lookup_get(&self, sha1: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "file_lookup_get(\"{}\") - X-Span-ID: {:?}", - sha1, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("file_lookup_get(\"{}\") - X-Span-ID: {:?}", sha1, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_post( - &self, - body: Option, - context: &Context, - ) -> Box + Send> { + fn file_post(&self, body: Option, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "file_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("file_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_id_get( - &self, - id: String, - context: &Context, - ) -> Box + Send> { + fn release_id_get(&self, id: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "release_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("release_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_lookup_get( - &self, - doi: String, - context: &Context, - ) -> Box + Send> { + fn release_lookup_get(&self, doi: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "release_lookup_get(\"{}\") - X-Span-ID: {:?}", - doi, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("release_lookup_get(\"{}\") - X-Span-ID: {:?}", doi, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_post( - &self, - body: Option, - context: &Context, - ) -> Box + Send> { + fn release_post(&self, body: Option, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "release_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("release_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn work_id_get( - &self, - id: String, - context: &Context, - ) -> Box + Send> { + fn work_id_get(&self, id: String, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "work_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("work_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn work_post( - &self, - body: Option, - context: &Context, - ) -> Box + Send> { + fn work_post(&self, body: Option, context: &Context) -> Box + Send> { let context = context.clone(); - println!( - "work_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("")).clone() - ); + println!("work_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("")).clone()); Box::new(futures::failed("Generic failure".into())) } } -- cgit v1.2.3