Skip to content

Commit

Permalink
Merge pull request #1646 from allengeorge/rustfmt_10
Browse files Browse the repository at this point in the history
Reformat rust code with rustfmt 1.0

Client: rs
  • Loading branch information
allengeorge committed Dec 17, 2018
2 parents 2b7365c + ef7a189 commit f4b1785
Show file tree
Hide file tree
Showing 20 changed files with 669 additions and 784 deletions.
69 changes: 63 additions & 6 deletions .rustfmt.toml
@@ -1,7 +1,64 @@
max_width = 100
fn_args_layout = "Block"
array_layout = "Block"
where_style = "Rfc"
generics_indent = "Block"
fn_call_style = "Block"
reorder_imported_names = true
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
use_small_heuristics = "Default"
indent_style = "Block"
wrap_comments = false
format_doc_comments = false
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
license_template_path = ""
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
merge_imports = false
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
force_multiline_blocks = false
fn_args_density = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.0.0"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
report_todo = "Never"
report_fixme = "Never"
ignore = []
emit_mode = "Files"
make_backup = false
158 changes: 58 additions & 100 deletions lib/rs/src/errors.rs
Expand Up @@ -198,8 +198,9 @@ impl Error {
/// Create an `ApplicationError` from its wire representation.
///
/// Application code **should never** call this method directly.
pub fn read_application_error_from_in_protocol(i: &mut TInputProtocol,)
-> ::Result<ApplicationError> {
pub fn read_application_error_from_in_protocol(
i: &mut TInputProtocol,
) -> ::Result<ApplicationError> {
let mut message = "general remote error".to_owned();
let mut kind = ApplicationErrorKind::Unknown;

Expand All @@ -224,9 +225,8 @@ impl Error {
}
2 => {
let remote_type_as_int = i.read_i32()?;
let remote_kind: ApplicationErrorKind =
TryFrom::try_from(remote_type_as_int)
.unwrap_or(ApplicationErrorKind::Unknown);
let remote_kind: ApplicationErrorKind = TryFrom::try_from(remote_type_as_int)
.unwrap_or(ApplicationErrorKind::Unknown);
i.read_field_end()?;
kind = remote_kind;
}
Expand All @@ -238,12 +238,10 @@ impl Error {

i.read_struct_end()?;

Ok(
ApplicationError {
kind: kind,
message: message,
},
)
Ok(ApplicationError {
kind: kind,
message: message,
})
}

/// Convert an `ApplicationError` into its wire representation and write
Expand All @@ -254,7 +252,9 @@ impl Error {
e: &ApplicationError,
o: &mut TOutputProtocol,
) -> ::Result<()> {
o.write_struct_begin(&TStructIdentifier { name: "TApplicationException".to_owned() },)?;
o.write_struct_begin(&TStructIdentifier {
name: "TApplicationException".to_owned(),
})?;

let message_field = TFieldIdentifier::new("message", TType::String, 1);
let type_field = TFieldIdentifier::new("type", TType::I32, 2);
Expand Down Expand Up @@ -309,23 +309,19 @@ impl Display for Error {

impl From<String> for Error {
fn from(s: String) -> Self {
Error::Application(
ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: s,
},
)
Error::Application(ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: s,
})
}
}

impl<'a> From<&'a str> for Error {
fn from(s: &'a str) -> Self {
Error::Application(
ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: String::from(s),
},
)
Error::Application(ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: String::from(s),
})
}
}

Expand Down Expand Up @@ -427,77 +423,51 @@ impl TryFrom<i32> for TransportErrorKind {
4 => Ok(TransportErrorKind::EndOfFile),
5 => Ok(TransportErrorKind::NegativeSize),
6 => Ok(TransportErrorKind::SizeLimit),
_ => {
Err(
Error::Protocol(
ProtocolError {
kind: ProtocolErrorKind::Unknown,
message: format!("cannot convert {} to TransportErrorKind", from),
},
),
)
}
_ => Err(Error::Protocol(ProtocolError {
kind: ProtocolErrorKind::Unknown,
message: format!("cannot convert {} to TransportErrorKind", from),
})),
}
}
}

impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
match err.kind() {
io::ErrorKind::ConnectionReset |
io::ErrorKind::ConnectionRefused |
io::ErrorKind::NotConnected => {
Error::Transport(
TransportError {
kind: TransportErrorKind::NotOpen,
message: err.description().to_owned(),
},
)
}
io::ErrorKind::AlreadyExists => {
Error::Transport(
TransportError {
kind: TransportErrorKind::AlreadyOpen,
message: err.description().to_owned(),
},
)
}
io::ErrorKind::TimedOut => {
Error::Transport(
TransportError {
kind: TransportErrorKind::TimedOut,
message: err.description().to_owned(),
},
)
}
io::ErrorKind::UnexpectedEof => {
Error::Transport(
TransportError {
kind: TransportErrorKind::EndOfFile,
message: err.description().to_owned(),
},
)
}
io::ErrorKind::ConnectionReset
| io::ErrorKind::ConnectionRefused
| io::ErrorKind::NotConnected => Error::Transport(TransportError {
kind: TransportErrorKind::NotOpen,
message: err.description().to_owned(),
}),
io::ErrorKind::AlreadyExists => Error::Transport(TransportError {
kind: TransportErrorKind::AlreadyOpen,
message: err.description().to_owned(),
}),
io::ErrorKind::TimedOut => Error::Transport(TransportError {
kind: TransportErrorKind::TimedOut,
message: err.description().to_owned(),
}),
io::ErrorKind::UnexpectedEof => Error::Transport(TransportError {
kind: TransportErrorKind::EndOfFile,
message: err.description().to_owned(),
}),
_ => {
Error::Transport(
TransportError {
kind: TransportErrorKind::Unknown,
message: err.description().to_owned(), // FIXME: use io error's debug string
},
)
Error::Transport(TransportError {
kind: TransportErrorKind::Unknown,
message: err.description().to_owned(), // FIXME: use io error's debug string
})
}
}
}
}

impl From<string::FromUtf8Error> for Error {
fn from(err: string::FromUtf8Error) -> Self {
Error::Protocol(
ProtocolError {
kind: ProtocolErrorKind::InvalidData,
message: err.description().to_owned(), // FIXME: use fmt::Error's debug string
},
)
Error::Protocol(ProtocolError {
kind: ProtocolErrorKind::InvalidData,
message: err.description().to_owned(), // FIXME: use fmt::Error's debug string
})
}
}

Expand Down Expand Up @@ -583,16 +553,10 @@ impl TryFrom<i32> for ProtocolErrorKind {
4 => Ok(ProtocolErrorKind::BadVersion),
5 => Ok(ProtocolErrorKind::NotImplemented),
6 => Ok(ProtocolErrorKind::DepthLimit),
_ => {
Err(
Error::Protocol(
ProtocolError {
kind: ProtocolErrorKind::Unknown,
message: format!("cannot convert {} to ProtocolErrorKind", from),
},
),
)
}
_ => Err(Error::Protocol(ProtocolError {
kind: ProtocolErrorKind::Unknown,
message: format!("cannot convert {} to ProtocolErrorKind", from),
})),
}
}
}
Expand Down Expand Up @@ -697,16 +661,10 @@ impl TryFrom<i32> for ApplicationErrorKind {
8 => Ok(ApplicationErrorKind::InvalidTransform),
9 => Ok(ApplicationErrorKind::InvalidProtocol),
10 => Ok(ApplicationErrorKind::UnsupportedClientType),
_ => {
Err(
Error::Application(
ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: format!("cannot convert {} to ApplicationErrorKind", from),
},
),
)
}
_ => Err(Error::Application(ApplicationError {
kind: ApplicationErrorKind::Unknown,
message: format!("cannot convert {} to ApplicationErrorKind", from),
})),
}
}
}
12 changes: 5 additions & 7 deletions lib/rs/src/lib.rs
Expand Up @@ -63,13 +63,11 @@ extern crate log;
/// return the value contained in the result, i.e. `expr.unwrap()`.
#[cfg(test)]
macro_rules! assert_success {
($e: expr) => {
{
let res = $e;
assert!(res.is_ok());
res.unwrap()
}
}
($e: expr) => {{
let res = $e;
assert!(res.is_ok());
res.unwrap()
}};
}

pub mod protocol;
Expand Down

0 comments on commit f4b1785

Please sign in to comment.