Skip to content

Commit cccfd36

Browse files
formatting
1 parent 1b7edcf commit cccfd36

File tree

5 files changed

+27
-65
lines changed

5 files changed

+27
-65
lines changed

amqp-lib/src/types/amqp_type.rs

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
use std::hash::Hash;
22

3-
use bigdecimal::BigDecimal;
4-
use indexmap::IndexMap;
3+
use crate::error::AppError;
54
use crate::types::binary::Binary;
65
use crate::types::collection::*;
76
use crate::types::decimal::*;
8-
use crate::error::AppError;
9-
7+
use bigdecimal::BigDecimal;
8+
use indexmap::IndexMap;
109

1110
pub trait Hashable: std::hash::Hash {}
1211
pub trait Encode {
1312
fn encode(&self) -> Encoded;
1413
}
1514

16-
pub trait Decode<'a>: From<&'a [u8]> + Encode {}
17-
15+
pub trait Decode<'a>: From<&'a [u8]> + Encode {}
1816

1917
pub struct Encoded {
2018
constructor: u8,
21-
data: Option<Vec<u8>>
19+
data: Option<Vec<u8>>,
2220
}
2321

2422
impl Encoded {
@@ -28,20 +26,21 @@ impl Encoded {
2826

2927
pub fn data_len(&self) -> usize {
3028
match &self.data {
31-
Some(data) => data.len().into(),
32-
None => 0
29+
Some(data) => data.len(),
30+
None => 0,
3331
}
3432
}
3533
}
3634

37-
3835
impl From<u8> for Encoded {
3936
fn from(value: u8) -> Self {
40-
Encoded { constructor: value, data: None }
37+
Encoded {
38+
constructor: value,
39+
data: None,
40+
}
4141
}
4242
}
4343

44-
4544
#[derive(Hash, Eq, PartialEq)]
4645
pub struct Symbol(String);
4746
#[derive(Hash, Eq, PartialEq)]
@@ -112,7 +111,6 @@ impl Encode for AmqpType {
112111
Self::Array(val) => val.encode(),
113112
}
114113
}
115-
116114
}
117115

118116
impl Hash for Float {
@@ -127,7 +125,6 @@ impl Hash for Double {
127125
}
128126
}
129127

130-
131128
impl PartialEq for Float {
132129
fn eq(&self, other: &Self) -> bool {
133130
self.0.to_bits() == other.0.to_bits()
@@ -140,7 +137,6 @@ impl PartialEq for Float {
140137

141138
impl Eq for Float {}
142139

143-
144140
impl PartialEq for Double {
145141
fn eq(&self, other: &Self) -> bool {
146142
self.0.to_bits() == self.0.to_bits()
@@ -151,7 +147,6 @@ impl PartialEq for Double {
151147
}
152148
}
153149

154-
155150
impl Eq for Double {}
156151
impl From<u8> for Constructor {
157152
fn from(value: u8) -> Self {
@@ -163,7 +158,6 @@ impl Encode for Timestamp {
163158
fn encode(&self) -> Encoded {
164159
0x83.into()
165160
}
166-
167161
}
168162
impl From<Timestamp> for AmqpType {
169163
fn from(value: Timestamp) -> Self {
@@ -189,57 +183,48 @@ impl Encode for u8 {
189183
fn encode(&self) -> Encoded {
190184
0x50.into()
191185
}
192-
193186
}
194187

195188
impl Encode for u16 {
196189
fn encode(&self) -> Encoded {
197190
0x60.into()
198191
}
199-
200192
}
201193

202194
impl Encode for i8 {
203195
fn encode(&self) -> Encoded {
204196
0x51.into()
205197
}
206-
207198
}
208199

209200
impl Encode for i16 {
210201
fn encode(&self) -> Encoded {
211202
0x61.into()
212203
}
213-
214204
}
215205

216206
impl Encode for Float {
217207
fn encode(&self) -> Encoded {
218208
0x72.into()
219209
}
220-
221210
}
222211

223212
impl Encode for Double {
224213
fn encode(&self) -> Encoded {
225214
0x82.into()
226215
}
227-
228216
}
229217

230218
impl Encode for char {
231219
fn encode(&self) -> Encoded {
232220
0x73.into()
233221
}
234-
235222
}
236223

237-
238224
impl Encode for Uuid {
239225
fn encode(&self) -> Encoded {
240226
0x98.into()
241227
}
242-
243228
}
244229
impl Encode for u32 {
245230
fn encode(&self) -> Encoded {
@@ -249,7 +234,6 @@ impl Encode for u32 {
249234
_ => 0x70.into(),
250235
}
251236
}
252-
253237
}
254238

255239
impl Encode for u64 {
@@ -260,7 +244,6 @@ impl Encode for u64 {
260244
_ => 0x80.into(),
261245
}
262246
}
263-
264247
}
265248

266249
impl Encode for i32 {
@@ -270,7 +253,6 @@ impl Encode for i32 {
270253
_ => 0x71.into(),
271254
}
272255
}
273-
274256
}
275257

276258
impl Encode for i64 {
@@ -280,7 +262,6 @@ impl Encode for i64 {
280262
_ => 0x81.into(),
281263
}
282264
}
283-
284265
}
285266

286267
impl Encode for String {
@@ -290,27 +271,23 @@ impl Encode for String {
290271
_ => 0xb1.into(),
291272
}
292273
}
293-
294274
}
295275

296276
impl Encode for Symbol {
297277
fn encode(&self) -> Encoded {
298278
match self.0.len() {
299279
x if x <= 255 => 0xa3.into(),
300-
_ => 0xb1.into()
280+
_ => 0xb1.into(),
301281
}
302282
}
303-
304283
}
305284

306285
impl Encode for Described {
307286
fn encode(&self) -> Encoded {
308287
todo!()
309288
}
310-
311289
}
312290

313-
314291
impl From<bool> for AmqpType {
315292
fn from(value: bool) -> Self {
316293
AmqpType::Boolean(value)
@@ -395,7 +372,6 @@ impl From<char> for AmqpType {
395372
}
396373
}
397374

398-
399375
impl From<Uuid> for AmqpType {
400376
fn from(value: Uuid) -> Self {
401377
AmqpType::Uuid(value)
@@ -426,7 +402,6 @@ impl From<Symbol> for AmqpType {
426402
}
427403
}
428404

429-
430405
impl From<List> for AmqpType {
431406
fn from(value: List) -> Self {
432407
AmqpType::List(value)
@@ -650,7 +625,7 @@ mod tests {
650625
#[test]
651626
fn amqp_type_can_construct_list_with_more_than_255_elements() {
652627
let mut arr = vec![];
653-
for i in 0 .. 500 {
628+
for i in 0..500 {
654629
arr.push(i.into())
655630
}
656631
let val = AmqpType::List(arr.into());
@@ -660,12 +635,11 @@ mod tests {
660635
#[test]
661636
fn amqp_type_can_construct_list_with_less_than_255_elements_and_larger_than_255_bytes() {
662637
let mut arr = vec![];
663-
for i in 0 .. 100 {
638+
for i in 0..100 {
664639
arr.push("aaaaaaaaaaaaaaaaaaaa".into());
665640
}
666641
let val = AmqpType::List(arr.into());
667642
assert_eq!(val.encode().constructor(), 0xd0);
668-
669643
}
670644

671645
#[test]
@@ -677,7 +651,7 @@ mod tests {
677651
#[test]
678652
fn amqp_type_can_construct_map_with_less_more_255_elements() {
679653
let mut map = IndexMap::new();
680-
for i in 1 .. 500 {
654+
for i in 1..500 {
681655
map.insert(i.into(), i.into());
682656
}
683657
let val = AmqpType::Map(map.into());
@@ -692,13 +666,11 @@ mod tests {
692666

693667
#[test]
694668
fn amqp_type_can_construct_array_with_more_than_255_elements() {
695-
696669
let mut arr = vec![];
697-
for i in 0 .. 500 {
670+
for i in 0..500 {
698671
arr.push(i.into())
699672
}
700673
let val = AmqpType::Array(arr.into());
701674
assert_eq!(val.encode().constructor(), 0xf0);
702-
703675
}
704676
}

amqp-lib/src/types/binary.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use crate::types::amqp_type::{Encode, Constructor};
1+
use crate::types::amqp_type::{Constructor, Encode};
22

33
use super::amqp_type::Encoded;
44

55
#[derive(Hash, Eq, PartialEq)]
66
pub struct Binary(Vec<u8>);
77

8-
98
impl Encode for Binary {
109
fn encode(&self) -> Encoded {
1110
todo!()

amqp-lib/src/types/collection.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use std::hash::Hash;
1+
use crate::types::amqp_type::{AmqpType, Constructor, Encode};
22
use indexmap::IndexMap;
3-
use crate::types::amqp_type::{Encode, Constructor, AmqpType};
3+
use std::hash::Hash;
44

55
use super::amqp_type::Encoded;
66

7-
87
#[derive(Hash, Eq, PartialEq)]
98
pub struct List(Vec<AmqpType>);
109
#[derive(Hash, Eq, PartialEq)]
@@ -14,15 +13,12 @@ pub struct Map(IndexMap<AmqpType, AmqpType>);
1413

1514
impl Encode for List {
1615
fn encode(&self) -> Encoded {
17-
let encoded_list: Vec<Encoded> = self.0.iter()
18-
.map(|x| x.encode())
19-
.collect();
20-
let byte_size = encoded_list.iter()
21-
.fold(0, |acc, x| acc + x.data_len());
16+
let encoded_list: Vec<Encoded> = self.0.iter().map(|x| x.encode()).collect();
17+
let byte_size = encoded_list.iter().fold(0, |acc, x| acc + x.data_len());
2218
match (encoded_list.len(), byte_size) {
2319
(0, _) => 0x45.into(),
2420
(len, size) if len <= 255 && size < 256 => 0xc0.into(),
25-
(_, _) => 0xd0.into()
21+
(_, _) => 0xd0.into(),
2622
}
2723
}
2824
}
@@ -31,16 +27,15 @@ impl Encode for Map {
3127
fn encode(&self) -> Encoded {
3228
todo!()
3329
}
34-
3530
}
3631

3732
impl Encode for Array {
38-
fn encode (&self) -> Encoded{
33+
fn encode(&self) -> Encoded {
3934
todo!()
4035
}
4136
}
4237

43-
impl From<Vec<AmqpType>> for List{
38+
impl From<Vec<AmqpType>> for List {
4439
fn from(value: Vec<AmqpType>) -> Self {
4540
List(value)
4641
}
@@ -63,4 +58,3 @@ impl Hash for Map {
6358
todo!()
6459
}
6560
}
66-

amqp-lib/src/types/decimal.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1+
use crate::types::amqp_type::{Constructor, Encode};
12
use bigdecimal::BigDecimal;
2-
use crate::types::amqp_type::{Encode, Constructor};
33

44
use super::amqp_type::Encoded;
55

6-
76
#[derive(Hash, Eq, PartialEq)]
87
pub struct Decimal32(BigDecimal);
98
#[derive(Hash, Eq, PartialEq)]
109
pub struct Decimal64(BigDecimal);
1110
#[derive(Hash, Eq, PartialEq)]
1211
pub struct Decimal128(BigDecimal);
1312

14-
15-
1613
impl Encode for Decimal32 {
1714
fn encode(&self) -> Encoded {
1815
0x74.into()
@@ -26,7 +23,7 @@ impl Encode for Decimal64 {
2623
}
2724

2825
impl Encode for Decimal128 {
29-
fn encode(&self) -> Encoded{
26+
fn encode(&self) -> Encoded {
3027
0x94.into()
3128
}
3229
}

amqp-lib/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
pub mod amqp_type;
2-
pub mod decimal;
32
pub mod binary;
43
pub mod collection;
4+
pub mod decimal;

0 commit comments

Comments
 (0)