Skip to content

Commit 7559fc5

Browse files
committed
Cargo fmt
1 parent 033c49b commit 7559fc5

11 files changed

Lines changed: 137 additions & 147 deletions

File tree

benches/arraystring.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
extern crate arrayvec;
3-
#[macro_use] extern crate bencher;
2+
#[macro_use]
3+
extern crate bencher;
44

55
use arrayvec::ArrayString;
66

@@ -10,8 +10,7 @@ fn try_push_c(b: &mut Bencher) {
1010
let mut v = ArrayString::<512>::new();
1111
b.iter(|| {
1212
v.clear();
13-
while v.try_push('c').is_ok() {
14-
}
13+
while v.try_push('c').is_ok() {}
1514
v.len()
1615
});
1716
b.bytes = v.capacity() as u64;
@@ -21,8 +20,7 @@ fn try_push_alpha(b: &mut Bencher) {
2120
let mut v = ArrayString::<512>::new();
2221
b.iter(|| {
2322
v.clear();
24-
while v.try_push('α').is_ok() {
25-
}
23+
while v.try_push('α').is_ok() {}
2624
v.len()
2725
});
2826
b.bytes = v.capacity() as u64;
@@ -85,6 +83,13 @@ fn push_string(b: &mut Bencher) {
8583
b.bytes = v.capacity() as u64;
8684
}
8785

88-
benchmark_group!(benches, try_push_c, try_push_alpha, try_push_string, push_c,
89-
push_alpha, push_string);
86+
benchmark_group!(
87+
benches,
88+
try_push_c,
89+
try_push_alpha,
90+
try_push_string,
91+
push_c,
92+
push_alpha,
93+
push_string
94+
);
9095
benchmark_main!(benches);

benches/extend.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
21
extern crate arrayvec;
3-
#[macro_use] extern crate bencher;
2+
#[macro_use]
3+
extern crate bencher;
44

55
use std::io::Write;
66

77
use arrayvec::ArrayVec;
88

9-
use bencher::Bencher;
109
use bencher::black_box;
10+
use bencher::Bencher;
1111

1212
fn extend_with_constant(b: &mut Bencher) {
1313
let mut v = ArrayVec::<u8, 512>::new();
@@ -67,12 +67,13 @@ fn extend_from_slice(b: &mut Bencher) {
6767
b.bytes = v.capacity() as u64;
6868
}
6969

70-
benchmark_group!(benches,
71-
extend_with_constant,
72-
extend_with_range,
73-
extend_with_slice,
74-
extend_with_write,
75-
extend_from_slice
70+
benchmark_group!(
71+
benches,
72+
extend_with_constant,
73+
extend_with_range,
74+
extend_with_slice,
75+
extend_with_write,
76+
extend_from_slice
7677
);
7778

7879
benchmark_main!(benches);

src/array_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
2525
extern crate alloc;
2626

2727
#[cfg(all(not(feature = "std"), feature = "borsh"))]
28-
use alloc::{string::ToString, format};
28+
use alloc::{format, string::ToString};
2929

3030
/// A string with a fixed capacity.
3131
///

src/arrayvec_impl.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@ pub(crate) trait ArrayVecImpl {
1616
/// Return a slice containing all elements of the vector.
1717
fn as_slice(&self) -> &[Self::Item] {
1818
let len = self.len();
19-
unsafe {
20-
slice::from_raw_parts(self.as_ptr(), len)
21-
}
19+
unsafe { slice::from_raw_parts(self.as_ptr(), len) }
2220
}
2321

2422
/// Return a mutable slice containing all elements of the vector.
2523
fn as_mut_slice(&mut self) -> &mut [Self::Item] {
2624
let len = self.len();
27-
unsafe {
28-
std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
29-
}
25+
unsafe { std::slice::from_raw_parts_mut(self.as_mut_ptr(), len) }
3026
}
3127

3228
/// Return a raw pointer to the vector's buffer.
@@ -84,4 +80,3 @@ pub(crate) trait ArrayVecImpl {
8480
}
8581
}
8682
}
87-

src/char.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// Original authors: alexchrichton, bluss
1212

1313
// UTF-8 ranges and tags for encoding characters
14-
const TAG_CONT: u8 = 0b1000_0000;
15-
const TAG_TWO_B: u8 = 0b1100_0000;
14+
const TAG_CONT: u8 = 0b1000_0000;
15+
const TAG_TWO_B: u8 = 0b1100_0000;
1616
const TAG_THREE_B: u8 = 0b1110_0000;
17-
const TAG_FOUR_B: u8 = 0b1111_0000;
18-
const MAX_ONE_B: u32 = 0x80;
19-
const MAX_TWO_B: u32 = 0x800;
20-
const MAX_THREE_B: u32 = 0x10000;
17+
const TAG_FOUR_B: u8 = 0b1111_0000;
18+
const MAX_ONE_B: u32 = 0x80;
19+
const MAX_TWO_B: u32 = 0x800;
20+
const MAX_THREE_B: u32 = 0x10000;
2121

2222
/// Placeholder
2323
pub struct EncodeUtf8Error;
@@ -29,8 +29,7 @@ pub struct EncodeUtf8Error;
2929
///
3030
/// Safety: `ptr` must be writable for `len` bytes.
3131
#[inline]
32-
pub unsafe fn encode_utf8(ch: char, ptr: *mut u8, len: usize) -> Result<usize, EncodeUtf8Error>
33-
{
32+
pub unsafe fn encode_utf8(ch: char, ptr: *mut u8, len: usize) -> Result<usize, EncodeUtf8Error> {
3433
let code = ch as u32;
3534
if code < MAX_ONE_B && len >= 1 {
3635
ptr.add(0).write(code as u8);
@@ -41,28 +40,29 @@ pub unsafe fn encode_utf8(ch: char, ptr: *mut u8, len: usize) -> Result<usize, E
4140
return Ok(2);
4241
} else if code < MAX_THREE_B && len >= 3 {
4342
ptr.add(0).write((code >> 12 & 0x0F) as u8 | TAG_THREE_B);
44-
ptr.add(1).write((code >> 6 & 0x3F) as u8 | TAG_CONT);
43+
ptr.add(1).write((code >> 6 & 0x3F) as u8 | TAG_CONT);
4544
ptr.add(2).write((code & 0x3F) as u8 | TAG_CONT);
4645
return Ok(3);
4746
} else if len >= 4 {
4847
ptr.add(0).write((code >> 18 & 0x07) as u8 | TAG_FOUR_B);
4948
ptr.add(1).write((code >> 12 & 0x3F) as u8 | TAG_CONT);
50-
ptr.add(2).write((code >> 6 & 0x3F) as u8 | TAG_CONT);
49+
ptr.add(2).write((code >> 6 & 0x3F) as u8 | TAG_CONT);
5150
ptr.add(3).write((code & 0x3F) as u8 | TAG_CONT);
5251
return Ok(4);
5352
};
5453
Err(EncodeUtf8Error)
5554
}
5655

57-
5856
#[test]
5957
#[cfg_attr(miri, ignore)] // Miri is too slow
6058
fn test_encode_utf8() {
6159
// Test that all codepoints are encoded correctly
6260
let mut data = [0u8; 16];
6361
for codepoint in 0..=(std::char::MAX as u32) {
6462
if let Some(ch) = std::char::from_u32(codepoint) {
65-
for elt in &mut data { *elt = 0; }
63+
for elt in &mut data {
64+
*elt = 0;
65+
}
6666
let ptr = data.as_mut_ptr();
6767
let len = data.len();
6868
unsafe {
@@ -89,4 +89,3 @@ fn test_encode_utf8_oob() {
8989
}
9090
}
9191
}
92-

src/errors.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::fmt;
2-
#[cfg(feature="std")]
1+
#[cfg(feature = "std")]
32
use std::any::Any;
4-
#[cfg(feature="std")]
3+
#[cfg(feature = "std")]
54
use std::error::Error;
5+
use std::fmt;
66

77
/// Error value indicating insufficient capacity
88
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
@@ -13,9 +13,7 @@ pub struct CapacityError<T = ()> {
1313
impl<T> CapacityError<T> {
1414
/// Create a new `CapacityError` from `element`.
1515
pub const fn new(element: T) -> CapacityError<T> {
16-
CapacityError {
17-
element: element,
18-
}
16+
CapacityError { element: element }
1917
}
2018

2119
/// Extract the overflowing element
@@ -31,7 +29,7 @@ impl<T> CapacityError<T> {
3129

3230
const CAPERROR: &'static str = "insufficient capacity";
3331

34-
#[cfg(feature="std")]
32+
#[cfg(feature = "std")]
3533
/// Requires `features="std"`.
3634
impl<T: Any> Error for CapacityError<T> {}
3735

@@ -46,4 +44,3 @@ impl<T> fmt::Debug for CapacityError<T> {
4644
write!(f, "{}: {}", "CapacityError", CAPERROR)
4745
}
4846
}
49-

src/lib.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
//!
2020
//! This version of arrayvec requires Rust 1.51 or later.
2121
//!
22-
#![doc(html_root_url="https://docs.rs/arrayvec/0.7/")]
23-
22+
#![doc(html_root_url = "https://docs.rs/arrayvec/0.7/")]
2423
#![cfg_attr(not(feature = "std"), no_std)]
2524

26-
#[cfg(feature="serde")]
25+
#[cfg(feature = "serde")]
2726
extern crate serde;
2827

29-
#[cfg(not(feature="std"))]
28+
#[cfg(not(feature = "std"))]
3029
extern crate core as std;
3130

3231
#[cfg(not(target_pointer_width = "16"))]
@@ -45,7 +44,7 @@ macro_rules! assert_capacity_limit {
4544
panic!("ArrayVec: largest supported capacity is u16::MAX");
4645
}
4746
}
48-
}
47+
};
4948
}
5049

5150
macro_rules! assert_capacity_limit_const {
@@ -58,14 +57,14 @@ macro_rules! assert_capacity_limit_const {
5857
}
5958
}
6059

61-
mod arrayvec_impl;
62-
mod arrayvec;
6360
mod array_string;
61+
mod arrayvec;
62+
mod arrayvec_impl;
6463
mod char;
6564
mod errors;
6665
mod utils;
6766

6867
pub use crate::array_string::ArrayString;
6968
pub use crate::errors::CapacityError;
7069

71-
pub use crate::arrayvec::{ArrayVec, IntoIter, Drain};
70+
pub use crate::arrayvec::{ArrayVec, Drain, IntoIter};

src/utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ impl<T, const N: usize> MakeMaybeUninit<T, N> {
88

99
pub(crate) const ARRAY: [MaybeUninit<T>; N] = [Self::VALUE; N];
1010
}
11-

tests/borsh.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ fn assert_ser<T: borsh::BorshSerialize>(v: &T, expected_bytes: &[u8]) {
99
assert_eq!(actual_bytes, expected_bytes);
1010
}
1111

12-
fn assert_roundtrip<T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + fmt::Debug>(v: &T) {
12+
fn assert_roundtrip<T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + fmt::Debug>(
13+
v: &T,
14+
) {
1315
let mut bytes = Vec::new();
1416
v.serialize(&mut bytes).unwrap();
1517
let v_de = T::try_from_slice(&bytes).unwrap();
1618
assert_eq!(*v, v_de);
1719
}
1820

1921
mod array_vec {
22+
use super::{assert_roundtrip, assert_ser};
2023
use arrayvec::ArrayVec;
21-
use super::{assert_ser, assert_roundtrip};
2224

2325
#[test]
2426
fn test_empty() {
@@ -47,8 +49,8 @@ mod array_vec {
4749
}
4850

4951
mod array_string {
52+
use super::{assert_roundtrip, assert_ser};
5053
use arrayvec::ArrayString;
51-
use super::{assert_ser, assert_roundtrip};
5254

5355
#[test]
5456
fn test_empty() {

0 commit comments

Comments
 (0)