Skip to content

Commit 4ff7c72

Browse files
formatting
1 parent 0020db4 commit 4ff7c72

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

amqp-type/src/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ pub enum AppError {
55
#[error("Encountered an IO Error.")]
66
IoError(#[from] std::io::Error),
77
#[error("Error while trying to deserialize value of type `{0}`. Reason: {1}")]
8-
DeserializationError(String, String)
9-
8+
DeserializationError(String, String),
109
}

amqp-type/src/fixed_width/boolean.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::error::AppError;
12
use crate::serde::decode::Decode;
23
use crate::serde::encode::{Encode, Encoded};
3-
use crate::error::AppError;
44

55
#[cfg(not(feature = "zero-length-bools"))]
66
impl Encode for bool {
@@ -12,10 +12,8 @@ impl Encode for bool {
1212
}
1313
}
1414

15-
1615
#[cfg(feature = "zero-length-bools")]
1716
impl Encode for bool {
18-
1917
fn encode(&self) -> Encoded {
2018
match self {
2119
true => 0x41.into(),
@@ -24,60 +22,73 @@ impl Encode for bool {
2422
}
2523
}
2624

27-
28-
2925
#[cfg(not(feature = "zero-length-bools"))]
3026
impl Decode for bool {
31-
3227
fn can_decode(data: impl Iterator<Item = u8>) -> bool {
3328
let mut iter = data.into_iter().peekable();
3429
match iter.peek() {
3530
Some(0x56) => true,
36-
_ => false
31+
_ => false,
3732
}
3833
}
3934

40-
fn try_decode(mut iter: impl Iterator<Item = u8>) -> Result<Self, AppError> where Self: Sized {
35+
fn try_decode(mut iter: impl Iterator<Item = u8>) -> Result<Self, AppError>
36+
where
37+
Self: Sized,
38+
{
4139
let con = iter.next();
4240
let val = iter.next();
4341
match (con, val) {
4442
(Some(c), Some(v)) if c == 0x56 && v == 0x00 => Ok(false),
4543
(Some(c), Some(v)) if c == 0x56 && v == 0x01 => Ok(true),
46-
(Some(c), _) => Err(AppError::DeserializationError("bool".to_string(),format!("bool cannot be constructed from value {:#04x}", c))),
47-
(Some(c), None) => Err(AppError::DeserializationError("bool".to_string(), "Iterator was empty".to_string())),
48-
(None, _) => Err(AppError::DeserializationError("bool".to_string(), "Iterator was empty".to_string())),
44+
(Some(c), _) => Err(AppError::DeserializationError(
45+
"bool".to_string(),
46+
format!("bool cannot be constructed from value {:#04x}", c),
47+
)),
48+
(Some(c), None) => Err(AppError::DeserializationError(
49+
"bool".to_string(),
50+
"Iterator was empty".to_string(),
51+
)),
52+
(None, _) => Err(AppError::DeserializationError(
53+
"bool".to_string(),
54+
"Iterator was empty".to_string(),
55+
)),
4956
}
50-
5157
}
5258
}
5359

54-
55-
5660
#[cfg(feature = "zero-length-bools")]
5761
impl Decode for bool {
58-
5962
fn can_decode(data: Iterator<Item = u8>) -> bool {
6063
let mut iter = data.into_iter().peekable();
6164
match iter.peek() {
6265
Some(0x41) => true,
6366
Some(0x42) => true,
64-
_ => false
67+
_ => false,
6568
}
6669
}
6770

68-
fn try_decode(data: Iterator<Item = u8>) -> Result<Self, AppError> where Self: Sized {
71+
fn try_decode(data: Iterator<Item = u8>) -> Result<Self, AppError>
72+
where
73+
Self: Sized,
74+
{
6975
if let Some(val) = iter.next() {
7076
return match val {
7177
0x41 => Ok(true),
7278
0x42 => Ok(false),
73-
_ => Err(AppError::DeserializationError("bool".to_string(), format!("bool cannot be constructed from value {:#04x}", val)))
74-
}
79+
_ => Err(AppError::DeserializationError(
80+
"bool".to_string(),
81+
format!("bool cannot be constructed from value {:#04x}", val),
82+
)),
83+
};
7584
}
76-
Err(AppError::DeserializationError("bool".to_string(), "Iterator was empty".to_string()))
85+
Err(AppError::DeserializationError(
86+
"bool".to_string(),
87+
"Iterator was empty".to_string(),
88+
))
7789
}
7890
}
7991

80-
8192
#[cfg(test)]
8293
mod test {
8394
use super::*;
@@ -113,7 +124,6 @@ mod test {
113124
assert_eq!(bool::can_decode(val_false.into_iter()), false);
114125
}
115126

116-
117127
#[test]
118128
#[cfg(not(feature = "zero-length-bools"))]
119129
fn decode_returns_error_when_value_bytes_are_invalid() {
@@ -123,7 +133,6 @@ mod test {
123133
assert!(bool::try_decode(val_false.into_iter()).is_err());
124134
}
125135

126-
127136
#[test]
128137
#[cfg(not(feature = "zero-length-bools"))]
129138
fn try_decode_returns_correct_value_if_bytes_are_valid() {
@@ -132,7 +141,6 @@ mod test {
132141
assert_eq!(bool::try_decode(val_true.into_iter()).unwrap(), true);
133142
assert_eq!(bool::try_decode(val_false.into_iter()).unwrap(), false);
134143
}
135-
136144

137145
#[test]
138146
#[cfg(feature = "zero-length-bools")]

amqp-type/src/serde/decode.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::{
77
pub struct Constructor(u8);
88

99
pub trait Decode {
10-
fn try_decode(data: impl Iterator<Item = u8>) -> Result<Self, AppError> where Self: Sized;
10+
fn try_decode(data: impl Iterator<Item = u8>) -> Result<Self, AppError>
11+
where
12+
Self: Sized;
1113
fn can_decode(data: impl Iterator<Item = u8>) -> bool;
1214
}
1315

amqp-type/src/serde/encode.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl From<Encoded> for Vec<u8> {
7373
res.push(c);
7474
let mut size: Vec<u8> = match c {
7575
0xA => vec![data.len() as u8],
76-
_ => (data.len() as u32).to_be_bytes().to_vec()
76+
_ => (data.len() as u32).to_be_bytes().to_vec(),
7777
};
7878
res.append(&mut size);
7979
res.append(&mut data);
@@ -91,10 +91,8 @@ impl From<Encoded> for Vec<u8> {
9191
}
9292
}
9393

94-
95-
9694
impl From<u8> for Encoded {
9795
fn from(value: u8) -> Self {
9896
Encoded::Empty(value)
9997
}
100-
}
98+
}

0 commit comments

Comments
 (0)