Skip to content

Commit

Permalink
reformat: Rust 1.40.0 (rustfmt 1.4.9-stable (33e3667 2019-10-07))
Browse files Browse the repository at this point in the history
  • Loading branch information
davepacheco committed Jan 4, 2021
1 parent e4236d1 commit 7d12647
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 313 deletions.
9 changes: 3 additions & 6 deletions dropshot/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ async fn main() -> Result<(), String> {
* For simplicity, we'll configure an "info"-level logger that writes to
* stderr assuming that it's a terminal.
*/
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Info,
};
let config_logging =
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Info };
let log = config_logging
.to_logger("example-basic")
.map_err(|error| format!("failed to create logger: {}", error))?;
Expand Down Expand Up @@ -82,9 +81,7 @@ impl ExampleContext {
* Return a new ExampleContext.
*/
pub fn new() -> Arc<ExampleContext> {
Arc::new(ExampleContext {
counter: AtomicU64::new(0),
})
Arc::new(ExampleContext { counter: AtomicU64::new(0) })
}

/**
Expand Down
17 changes: 5 additions & 12 deletions dropshot/examples/pagination-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ async fn example_list_projects(
.map(|(_, project)| project.clone())
.collect()
}
WhichPage::Next(ProjectPage {
name: last_seen,
}) => {
WhichPage::Next(ProjectPage { name: last_seen }) => {
/* Return a list of the first "limit" projects after this name. */
tree.range((Bound::Excluded(last_seen.clone()), Bound::Unbounded))
.take(limit)
Expand All @@ -105,9 +103,7 @@ async fn example_list_projects(
Ok(HttpResponseOk(ResultsPage::new(
projects,
&EmptyScanParams {},
|p: &Project, _| ProjectPage {
name: p.name.clone(),
},
|p: &Project, _| ProjectPage { name: p.name.clone() },
)?))
}

Expand All @@ -131,9 +127,7 @@ async fn main() -> Result<(), String> {
let mut tree = BTreeMap::new();
for n in 1..1000 {
let name = format!("project{:03}", n);
let project = Project {
name: name.clone(),
};
let project = Project { name: name.clone() };
tree.insert(name, project);
}

Expand All @@ -145,9 +139,8 @@ async fn main() -> Result<(), String> {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
};
let config_logging =
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
let log = config_logging
.to_logger("example-pagination-basic")
.map_err(|error| format!("failed to create logger: {}", error))?;
Expand Down
51 changes: 21 additions & 30 deletions dropshot/examples/pagination-multiple-resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,25 @@ fn page_selector<T: HasIdentity>(
scan_params: &ExScanParams,
) -> ExPageSelector {
match scan_params {
ExScanParams {
sort: ExSortMode::ByIdAscending,
} => ExPageSelector::Id(Ascending, *item.id()),
ExScanParams {
sort: ExSortMode::ByIdDescending,
} => ExPageSelector::Id(Descending, *item.id()),
ExScanParams {
sort: ExSortMode::ByNameAscending,
} => ExPageSelector::Name(Ascending, item.name().to_string()),
ExScanParams {
sort: ExSortMode::ByNameDescending,
} => ExPageSelector::Name(Descending, item.name().to_string()),
ExScanParams { sort: ExSortMode::ByIdAscending } => {
ExPageSelector::Id(Ascending, *item.id())
}
ExScanParams { sort: ExSortMode::ByIdDescending } => {
ExPageSelector::Id(Descending, *item.id())
}
ExScanParams { sort: ExSortMode::ByNameAscending } => {
ExPageSelector::Name(Ascending, item.name().to_string())
}
ExScanParams { sort: ExSortMode::ByNameDescending } => {
ExPageSelector::Name(Descending, item.name().to_string())
}
}
}

fn scan_params(p: &WhichPage<ExScanParams, ExPageSelector>) -> ExScanParams {
ExScanParams {
sort: match p {
WhichPage::First(ExScanParams {
sort,
}) => sort.clone(),
WhichPage::First(ExScanParams { sort }) => sort.clone(),

WhichPage::Next(ExPageSelector::Id(Ascending, ..)) => {
ExSortMode::ByIdAscending
Expand Down Expand Up @@ -297,9 +295,8 @@ async fn main() -> Result<(), String> {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
};
let config_logging =
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
let log = config_logging
.to_logger("example-pagination-basic")
.map_err(|error| format!("failed to create logger: {}", error))?;
Expand Down Expand Up @@ -350,26 +347,20 @@ impl DataCollection {
};
for n in 1..1000 {
let pname = format!("project{:03}", n);
let project = Arc::new(Project {
id: Uuid::new_v4(),
name: pname.clone(),
});
let project =
Arc::new(Project { id: Uuid::new_v4(), name: pname.clone() });
data.projects_by_name.insert(pname.clone(), Arc::clone(&project));
data.projects_by_id.insert(project.id, project);

let dname = format!("disk{:03}", n);
let disk = Arc::new(Disk {
id: Uuid::new_v4(),
name: dname.clone(),
});
let disk =
Arc::new(Disk { id: Uuid::new_v4(), name: dname.clone() });
data.disks_by_name.insert(dname.clone(), Arc::clone(&disk));
data.disks_by_id.insert(disk.id, disk);

let iname = format!("disk{:03}", n);
let instance = Arc::new(Instance {
id: Uuid::new_v4(),
name: iname.clone(),
});
let instance =
Arc::new(Instance { id: Uuid::new_v4(), name: iname.clone() });
data.instances_by_name.insert(iname.clone(), Arc::clone(&instance));
data.instances_by_id.insert(instance.id, instance);
}
Expand Down
13 changes: 4 additions & 9 deletions dropshot/examples/pagination-multiple-sorts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ async fn example_list_projects(
let data = rqctx_to_data(rqctx);
let scan_params = ProjectScanParams {
sort: match &pag_params.page {
WhichPage::First(ProjectScanParams {
sort,
}) => sort.clone(),
WhichPage::First(ProjectScanParams { sort }) => sort.clone(),

WhichPage::Next(ProjectScanPageSelector::Name(Ascending, ..)) => {
ProjectSort::ByNameAscending
Expand Down Expand Up @@ -318,9 +316,8 @@ async fn main() -> Result<(), String> {
bind_address: SocketAddr::from((Ipv4Addr::LOCALHOST, port)),
request_body_max_bytes: 1024,
};
let config_logging = ConfigLogging::StderrTerminal {
level: ConfigLoggingLevel::Debug,
};
let config_logging =
ConfigLogging::StderrTerminal { level: ConfigLoggingLevel::Debug };
let log = config_logging
.to_logger("example-pagination-basic")
.map_err(|error| format!("failed to create logger: {}", error))?;
Expand All @@ -346,9 +343,7 @@ fn print_example_requests(log: slog::Logger, addr: &SocketAddr) {
ProjectSort::ByMtimeDescending,
];
for mode in all_modes {
let to_print = ProjectScanParams {
sort: mode,
};
let to_print = ProjectScanParams { sort: mode };
let query_string = serde_urlencoded::to_string(to_print).unwrap();
let uri = Uri::builder()
.scheme("http")
Expand Down
4 changes: 1 addition & 3 deletions dropshot/examples/petstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ async fn find_pets_by_tags(
tags: None,
status: None,
};
tmp = FindByTagsScanParams {
tags: page_selector.tags.clone(),
};
tmp = FindByTagsScanParams { tags: page_selector.tags.clone() };
(vec![pet], &tmp)
}
};
Expand Down
30 changes: 11 additions & 19 deletions dropshot/src/api_description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ pub enum ApiSchemaGenerator {
impl std::fmt::Debug for ApiSchemaGenerator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ApiSchemaGenerator::Gen {
..
} => f.write_str("[schema generator]"),
ApiSchemaGenerator::Gen { .. } => f.write_str("[schema generator]"),
ApiSchemaGenerator::Static(schema) => {
f.write_str(format!("{:?}", schema).as_str())
}
Expand All @@ -185,9 +183,7 @@ pub struct ApiDescription {

impl ApiDescription {
pub fn new() -> Self {
ApiDescription {
router: HttpRouter::new(),
}
ApiDescription { router: HttpRouter::new() }
}

/**
Expand Down Expand Up @@ -385,10 +381,9 @@ impl ApiDescription {
}

let (name, js) = match &param.schema {
ApiSchemaGenerator::Gen {
name,
schema,
} => (Some(name()), schema(&mut generator)),
ApiSchemaGenerator::Gen { name, schema } => {
(Some(name()), schema(&mut generator))
}
ApiSchemaGenerator::Static(schema) => {
(None, schema.clone())
}
Expand Down Expand Up @@ -416,10 +411,9 @@ impl ApiDescription {

if let Some(schema) = &endpoint.response.schema {
let (name, js) = match schema {
ApiSchemaGenerator::Gen {
name,
schema,
} => (Some(name()), schema(&mut generator)),
ApiSchemaGenerator::Gen { name, schema } => {
(Some(name()), schema(&mut generator))
}
ApiSchemaGenerator::Static(schema) => {
(None, schema.clone())
}
Expand Down Expand Up @@ -831,11 +825,9 @@ fn box_reference_or<T>(
openapiv3::ReferenceOr::Item(schema) => {
openapiv3::ReferenceOr::boxed_item(schema)
}
openapiv3::ReferenceOr::Reference {
reference,
} => openapiv3::ReferenceOr::Reference {
reference,
},
openapiv3::ReferenceOr::Reference { reference } => {
openapiv3::ReferenceOr::Reference { reference }
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions dropshot/src/from_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ impl<'de, 'a> Deserializer<'de> for &'a mut MapDeserializer<'de> {
match self {
MapDeserializer::Map(map) => {
let x = Box::new(map.clone().into_iter());
visitor.visit_map(MapMapAccess {
iter: x,
value: None,
})
visitor.visit_map(MapMapAccess { iter: x, value: None })
}
MapDeserializer::Value(_) => Err(MapError(
"destination struct must be fully flattened".to_string(),
Expand Down
18 changes: 4 additions & 14 deletions dropshot/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,7 @@ where
* TODO-correctness: are query strings defined to be urlencoded in this way?
*/
match serde_urlencoded::from_str(raw_query_string) {
Ok(q) => Ok(Query {
inner: q,
}),
Ok(q) => Ok(Query { inner: q }),
Err(e) => Err(HttpError::for_bad_request(
None,
format!("unable to parse query string: {}", e),
Expand Down Expand Up @@ -610,9 +608,7 @@ where
rqctx: Arc<RequestContext>,
) -> Result<Path<PathType>, HttpError> {
let params: PathType = http_extract_path_params(&rqctx.path_variables)?;
Ok(Path {
inner: params,
})
Ok(Path { inner: params })
}

fn metadata() -> Vec<ApiEndpointParameter> {
Expand Down Expand Up @@ -849,9 +845,7 @@ where
let value: Result<BodyType, serde_json::Error> =
serde_json::from_slice(&body_bytes);
match value {
Ok(j) => Ok(TypedBody {
inner: j,
}),
Ok(j) => Ok(TypedBody { inner: j }),
Err(e) => Err(HttpError::for_bad_request(
None,
format!("unable to parse body: {}", e),
Expand Down Expand Up @@ -925,11 +919,7 @@ impl HttpResponse for Response<Body> {
Ok(self)
}
fn metadata() -> ApiEndpointResponse {
ApiEndpointResponse {
schema: None,
success: None,
description: None,
}
ApiEndpointResponse { schema: None, success: None, description: None }
}
}

Expand Down
40 changes: 20 additions & 20 deletions dropshot/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,14 @@ impl ConfigLogging {
log_name: S,
) -> Result<Logger, io::Error> {
match self {
ConfigLogging::StderrTerminal {
level,
} => {
ConfigLogging::StderrTerminal { level } => {
let decorator = slog_term::TermDecorator::new().build();
let drain =
slog_term::FullFormat::new(decorator).build().fuse();
Ok(async_root_logger(level, drain))
}

ConfigLogging::File {
level,
path,
if_exists,
} => {
ConfigLogging::File { level, path, if_exists } => {
let mut open_options = std::fs::OpenOptions::new();
open_options.write(true);
open_options.create(true);
Expand Down Expand Up @@ -527,12 +521,15 @@ mod test {
let time_after = chrono::offset::Utc::now();
let log_records = read_bunyan_log(&logpath);
let expected_hostname = hostname::get().unwrap().into_string().unwrap();
verify_bunyan_records(log_records.iter(), &BunyanLogRecordSpec {
name: Some("test-logger".to_string()),
hostname: Some(expected_hostname.clone()),
v: Some(0),
pid: Some(std::process::id()),
});
verify_bunyan_records(
log_records.iter(),
&BunyanLogRecordSpec {
name: Some("test-logger".to_string()),
hostname: Some(expected_hostname.clone()),
v: Some(0),
pid: Some(std::process::id()),
},
);
verify_bunyan_records_sequential(
log_records.iter(),
Some(&time_before),
Expand Down Expand Up @@ -569,12 +566,15 @@ mod test {
}

let log_records = read_bunyan_log(&logpath);
verify_bunyan_records(log_records.iter(), &BunyanLogRecordSpec {
name: Some("test-logger".to_string()),
hostname: Some(expected_hostname),
v: Some(0),
pid: Some(std::process::id()),
});
verify_bunyan_records(
log_records.iter(),
&BunyanLogRecordSpec {
name: Some("test-logger".to_string()),
hostname: Some(expected_hostname),
v: Some(0),
pid: Some(std::process::id()),
},
);
verify_bunyan_records_sequential(
log_records.iter(),
Some(&time_before),
Expand Down
Loading

0 comments on commit 7d12647

Please sign in to comment.