Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1203 from mozilla-services/feat/rustfmt-all
Browse files Browse the repository at this point in the history
rustfmt all the rust
  • Loading branch information
bbangert authored May 4, 2018
2 parents 4561031 + 517285b commit b8dca54
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 203 deletions.
26 changes: 17 additions & 9 deletions autopush_rs/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde_json;
use uuid::Uuid;

use errors::*;
use rt::{self, UnwindGuard, AutopushError};
use rt::{self, AutopushError, UnwindGuard};
use protocol;
use server::Server;

Expand Down Expand Up @@ -114,7 +114,6 @@ impl<F: FnOnce(&str) + Send> FnBox for F {
}
}


#[derive(Serialize)]
#[serde(tag = "command", rename_all = "snake_case")]
enum Call {
Expand Down Expand Up @@ -142,15 +141,19 @@ enum Call {
message_month: String,
},

DropUser { uaid: String },
DropUser {
uaid: String,
},

MigrateUser { uaid: String, message_month: String },
MigrateUser {
uaid: String,
message_month: String,
},

StoreMessages {
message_month: String,
messages: Vec<protocol::Notification>,
},

}

#[derive(Deserialize)]
Expand All @@ -172,7 +175,9 @@ pub struct HelloResponse {
#[derive(Deserialize)]
#[serde(untagged)]
pub enum RegisterResponse {
Success { endpoint: String },
Success {
endpoint: String,
},

Error {
error_msg: String,
Expand All @@ -184,7 +189,9 @@ pub enum RegisterResponse {
#[derive(Deserialize)]
#[serde(untagged)]
pub enum UnRegisterResponse {
Success { success: bool },
Success {
success: bool,
},

Error {
error_msg: String,
Expand Down Expand Up @@ -213,7 +220,6 @@ pub struct StoreMessagesResponse {
pub success: bool,
}


impl Server {
pub fn hello(&self, connected_at: &u64, uaid: Option<&Uuid>) -> MyFuture<HelloResponse> {
let ms = *connected_at as i64;
Expand Down Expand Up @@ -326,7 +332,9 @@ impl PythonCall {
let (tx, rx) = oneshot::channel();
let call = PythonCall {
input: serde_json::to_string(input).unwrap(),
output: Box::new(|json: &str| { drop(tx.send(json_or_error(json))); }),
output: Box::new(|json: &str| {
drop(tx.send(json_or_error(json)));
}),
};
let rx = Box::new(rx.then(|res| match res {
Ok(Ok(s)) => Ok(serde_json::from_str(&s)?),
Expand Down
27 changes: 18 additions & 9 deletions autopush_rs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use errors::*;
use protocol::{ClientMessage, Notification, ServerMessage, ServerNotification};
use server::Server;
use util::{ms_since_epoch, parse_user_agent, sec_since_epoch};
use util::ddb_helpers::{CheckStorageResponse};
use util::ddb_helpers::CheckStorageResponse;
use util::megaphone::{ClientServices, Service, ServiceClientInit};

// Created and handed to the AutopushServer
Expand Down Expand Up @@ -643,7 +643,11 @@ where
}
};

let SendThenWait { data, remaining_data, .. } = send.take();
let SendThenWait {
data,
remaining_data,
..
} = send.take();
if start_send {
transition!(SendThenWait {
remaining_data,
Expand Down Expand Up @@ -702,9 +706,11 @@ where
};
if let Some(delta) = service_delta {
transition!(SendThenWait {
remaining_data: vec![ServerMessage::Broadcast {
broadcasts: Service::into_hashmap(delta),
}],
remaining_data: vec![
ServerMessage::Broadcast {
broadcasts: Service::into_hashmap(delta),
},
],
poll_complete: false,
data,
});
Expand Down Expand Up @@ -825,9 +831,9 @@ where
.ok_or("unacked_stored_highest unset")?
.to_string();
let ddb_response = increment_storage.data.srv.ddb.increment_storage(
&webpush.message_month,
&webpush.uaid,
&timestamp
&webpush.message_month,
&webpush.uaid,
&timestamp,
);
transition!(AwaitIncrementStorage {
ddb_response,
Expand Down Expand Up @@ -894,7 +900,10 @@ where
.unacked_stored_notifs
.extend(messages.iter().cloned());
transition!(SendThenWait {
remaining_data: messages.into_iter().map(ServerMessage::Notification).collect(),
remaining_data: messages
.into_iter()
.map(ServerMessage::Notification)
.collect(),
poll_complete: false,
data,
})
Expand Down
36 changes: 14 additions & 22 deletions autopush_rs/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::str;
use std::rc::Rc;

use futures::future::ok;
use futures::{Stream, Future};
use futures::{Future, Stream};
use hyper::{Method, StatusCode};
use hyper;
use serde_json;
Expand Down Expand Up @@ -55,32 +55,24 @@ impl Service for Push {
if let Ok(msg) = serde_json::from_str(&s) {
match srv.notify_client(uaid, msg) {
Ok(_) => Ok(hyper::Response::new().with_status(StatusCode::Ok)),
_ => {
Ok(
hyper::Response::new()
.with_status(StatusCode::BadGateway)
.with_body("Client not available."),
)
}
_ => Ok(hyper::Response::new()
.with_status(StatusCode::BadGateway)
.with_body("Client not available.")),
}
} else {
Ok(
hyper::Response::new()
.with_status(hyper::StatusCode::BadRequest)
.with_body("Unable to decode body payload"),
)
Ok(hyper::Response::new()
.with_status(hyper::StatusCode::BadRequest)
.with_body("Unable to decode body payload"))
}
}))
}));
}
(&Method::Put, "notif", uaid) => {
match srv.check_client_storage(uaid) {
Ok(_) => response.set_status(StatusCode::Ok),
_ => {
response.set_status(StatusCode::BadGateway);
response.set_body("Client not available.");
}
(&Method::Put, "notif", uaid) => match srv.check_client_storage(uaid) {
Ok(_) => response.set_status(StatusCode::Ok),
_ => {
response.set_status(StatusCode::BadGateway);
response.set_body("Client not available.");
}
}
},
(_, "push", _) => response.set_status(StatusCode::MethodNotAllowed),
(_, "notif", _) => response.set_status(StatusCode::MethodNotAllowed),
_ => response.set_status(StatusCode::NotFound),
Expand Down
10 changes: 5 additions & 5 deletions autopush_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ extern crate serde;
extern crate serde_derive;
extern crate serde_dynamodb;
#[macro_use]
extern crate slog;
extern crate serde_json;
#[macro_use]
extern crate slog_scope;
extern crate slog_term;
extern crate slog;
extern crate slog_async;
extern crate slog_json;
extern crate slog_stdlog;
#[macro_use]
extern crate serde_json;
extern crate slog_scope;
extern crate slog_stdlog;
extern crate slog_term;
#[macro_use]
extern crate state_machine_future;
extern crate time;
Expand Down
6 changes: 3 additions & 3 deletions autopush_rs/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ pub enum ClientMessage {
broadcasts: HashMap<String, String>,
},

Ack { updates: Vec<ClientAck> },
Ack {
updates: Vec<ClientAck>,
},

Nack {
code: Option<i32>,
version: String,
},

}

#[derive(Deserialize)]
Expand Down Expand Up @@ -119,7 +120,6 @@ pub struct Notification {
pub headers: Option<HashMap<String, String>>,
}


fn default_ttl() -> u32 {
0
}
16 changes: 7 additions & 9 deletions autopush_rs/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ impl AutopushError {
let any: &Any = unsafe { mem::transmute((self.p1, self.p2)) };
// Similar to what libstd does, only check for `&'static str` and
// `String`.
any.downcast_ref::<&'static str>().map(|s| &s[..]).or_else(
|| {
any.downcast_ref::<String>().map(|s| &s[..])
},
)
any.downcast_ref::<&'static str>()
.map(|s| &s[..])
.or_else(|| any.downcast_ref::<String>().map(|s| &s[..]))
}

fn assert_empty(&self) {
Expand Down Expand Up @@ -98,17 +96,17 @@ pub extern "C" fn autopush_error_msg_len(err: *const AutopushError) -> usize {
/// returns null.
#[no_mangle]
pub extern "C" fn autopush_error_msg_ptr(err: *const AutopushError) -> *const u8 {
abort_on_panic(|| unsafe {
(*err).string().map(|s| s.as_ptr()).unwrap_or(ptr::null())
})
abort_on_panic(|| unsafe { (*err).string().map(|s| s.as_ptr()).unwrap_or(ptr::null()) })
}

/// Deallocates the internal `Box<Any>`, freeing any resources it contains.
///
/// The error itself can continue to be reused for future function calls.
#[no_mangle]
pub unsafe extern "C" fn autopush_error_cleanup(err: *mut AutopushError) {
abort_on_panic(|| { (&mut *err).cleanup(); });
abort_on_panic(|| {
(&mut *err).cleanup();
});
}

/// Helper structure to provide "unwind safety" to ensure we don't reuse values
Expand Down
Loading

0 comments on commit b8dca54

Please sign in to comment.