Skip to content

Commit cebae07

Browse files
committed
formatting: align formatting
Align to recent changes to formatting.
1 parent cd10951 commit cebae07

File tree

10 files changed

+136
-34
lines changed

10 files changed

+136
-34
lines changed

src/containers/fixed_capacity/string.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl FixedCapacityString {
3838
/// - Panics if the memory allocation fails.
3939
#[must_use]
4040
pub fn new(capacity: usize) -> Self {
41-
assert!(capacity <= u32::MAX as usize, "FixedCapacityString can hold at most u32::MAX bytes");
41+
assert!(
42+
capacity <= u32::MAX as usize,
43+
"FixedCapacityString can hold at most u32::MAX bytes"
44+
);
4245
Self {
4346
inner: GenericString::new(capacity as u32),
4447
}

src/containers/generic/queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use core::mem::needs_drop;
1616
use core::ops::Range;
1717
use core::ptr;
1818

19-
use crate::InsufficientCapacity;
2019
use crate::storage::Storage;
20+
use crate::InsufficientCapacity;
2121

2222
#[repr(C)]
2323
pub struct GenericQueue<T, S: Storage<T>> {

src/containers/generic/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use core::ops;
1616
use core::str;
1717

1818
use super::vec::GenericVec;
19-
use crate::InsufficientCapacity;
2019
use crate::storage::Storage;
20+
use crate::InsufficientCapacity;
2121

2222
/// A UTF-8 encoded string which is generic over its storage method.
2323
#[repr(transparent)]

src/containers/generic/vec.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use core::mem::needs_drop;
1717
use core::ops;
1818
use core::ptr;
1919

20-
use crate::InsufficientCapacity;
2120
use crate::storage::Storage;
21+
use crate::InsufficientCapacity;
2222

2323
#[repr(C)]
2424
pub struct GenericVec<T, S: Storage<T>> {
@@ -143,12 +143,14 @@ impl<T: Copy, S: Storage<T>> GenericVec<T, S> {
143143
/// If the vector has sufficient spare capacity, the operation succeeds and a reference to those elements is returned;
144144
/// otherwise, `Err(InsufficientCapacity)` is returned.
145145
pub fn extend_from_slice(&mut self, other: &[T]) -> Result<&mut [T], InsufficientCapacity> {
146-
let new_len = (self.len as usize).checked_add(other.len()).ok_or(InsufficientCapacity)?;
146+
let new_len = (self.len as usize)
147+
.checked_add(other.len())
148+
.ok_or(InsufficientCapacity)?;
147149
if new_len <= self.capacity() {
148150
let new_len = new_len as u32; // No overflow, because new_len <= capacity <= u32::MAX
149-
// SAFETY:
150-
// - `self.len <= new_len``, because the addition didn't overflow
151-
// - `new_len <= self.capacity()` as per check above
151+
// SAFETY:
152+
// - `self.len <= new_len``, because the addition didn't overflow
153+
// - `new_len <= self.capacity()` as per check above
152154
let target = unsafe { self.storage.subslice_mut(self.len, new_len) };
153155
// SAFETY:
154156
// - `other.as_ptr()` is valid for reads of `other.len()` elements, because it's a valid slice reference

src/containers/storage/heap.rs

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
// *******************************************************************************
1313

14-
use alloc::alloc::Layout;
1514
use alloc::alloc::alloc;
1615
use alloc::alloc::dealloc;
16+
use alloc::alloc::Layout;
1717
use core::marker::PhantomData;
1818
use core::mem::MaybeUninit;
1919
use core::ptr;
@@ -47,7 +47,12 @@ impl<T> Storage<T> for Heap<T> {
4747
///
4848
/// Panics if the memory allocation failed.
4949
fn new(capacity: u32) -> Self {
50-
Self::try_new(capacity).unwrap_or_else(|| panic!("failed to allocate {capacity} elements of {typ}", typ = core::any::type_name::<T>()))
50+
Self::try_new(capacity).unwrap_or_else(|| {
51+
panic!(
52+
"failed to allocate {capacity} elements of {typ}",
53+
typ = core::any::type_name::<T>()
54+
)
55+
})
5156
}
5257

5358
/// Tries to create a new instance with capacity for exactly the given number of elements.
@@ -147,11 +152,20 @@ mod tests {
147152
if capacity > 2 {
148153
let partial_slice = unsafe { instance.subslice(1, 2) };
149154
assert_eq!(partial_slice.len(), 1);
150-
assert_eq!(partial_slice as *const T, instance.elements.as_ptr().wrapping_add(1));
155+
assert_eq!(
156+
partial_slice as *const T,
157+
instance.elements.as_ptr().wrapping_add(1)
158+
);
151159

152160
let end_slice = unsafe { instance.subslice(capacity - 1, capacity) };
153161
assert_eq!(end_slice.len(), 1);
154-
assert_eq!(end_slice as *const T, instance.elements.as_ptr().wrapping_add(capacity as usize - 1));
162+
assert_eq!(
163+
end_slice as *const T,
164+
instance
165+
.elements
166+
.as_ptr()
167+
.wrapping_add(capacity as usize - 1)
168+
);
155169
}
156170
}
157171

@@ -178,11 +192,20 @@ mod tests {
178192
if capacity >= 2 {
179193
let partial_slice = unsafe { instance.subslice_mut(1, 2) };
180194
assert_eq!(partial_slice.len(), 1);
181-
assert_eq!(partial_slice as *mut T, instance.elements.as_ptr().wrapping_add(1));
195+
assert_eq!(
196+
partial_slice as *mut T,
197+
instance.elements.as_ptr().wrapping_add(1)
198+
);
182199

183200
let end_slice = unsafe { instance.subslice_mut(capacity - 1, capacity) };
184201
assert_eq!(end_slice.len(), 1);
185-
assert_eq!(end_slice as *mut T, instance.elements.as_ptr().wrapping_add(capacity as usize - 1));
202+
assert_eq!(
203+
end_slice as *mut T,
204+
instance
205+
.elements
206+
.as_ptr()
207+
.wrapping_add(capacity as usize - 1)
208+
);
186209
}
187210
}
188211

@@ -203,15 +226,30 @@ mod tests {
203226
assert_eq!(first_element.as_ptr(), instance.elements.as_ptr());
204227

205228
let last_element = unsafe { instance.element(capacity - 1) };
206-
assert_eq!(last_element.as_ptr(), instance.elements.as_ptr().wrapping_add(capacity as usize - 1));
229+
assert_eq!(
230+
last_element.as_ptr(),
231+
instance
232+
.elements
233+
.as_ptr()
234+
.wrapping_add(capacity as usize - 1)
235+
);
207236
}
208237

209238
if capacity >= 2 {
210239
let second_element = unsafe { instance.element(1) };
211-
assert_eq!(second_element.as_ptr(), instance.elements.as_ptr().wrapping_add(1));
240+
assert_eq!(
241+
second_element.as_ptr(),
242+
instance.elements.as_ptr().wrapping_add(1)
243+
);
212244

213245
let last_element = unsafe { instance.element(capacity - 2) };
214-
assert_eq!(last_element.as_ptr(), instance.elements.as_ptr().wrapping_add(capacity as usize - 2));
246+
assert_eq!(
247+
last_element.as_ptr(),
248+
instance
249+
.elements
250+
.as_ptr()
251+
.wrapping_add(capacity as usize - 2)
252+
);
215253
}
216254
}
217255

@@ -232,15 +270,30 @@ mod tests {
232270
assert_eq!(first_element.as_ptr(), instance.elements.as_ptr());
233271

234272
let last_element = unsafe { instance.element_mut(capacity - 1) };
235-
assert_eq!(last_element.as_ptr(), instance.elements.as_ptr().wrapping_add(capacity as usize - 1));
273+
assert_eq!(
274+
last_element.as_ptr(),
275+
instance
276+
.elements
277+
.as_ptr()
278+
.wrapping_add(capacity as usize - 1)
279+
);
236280
}
237281

238282
if capacity >= 2 {
239283
let second_element = unsafe { instance.element_mut(1) };
240-
assert_eq!(second_element.as_ptr(), instance.elements.as_ptr().wrapping_add(1));
284+
assert_eq!(
285+
second_element.as_ptr(),
286+
instance.elements.as_ptr().wrapping_add(1)
287+
);
241288

242289
let last_element = unsafe { instance.element_mut(capacity - 2) };
243-
assert_eq!(last_element.as_ptr(), instance.elements.as_ptr().wrapping_add(capacity as usize - 2));
290+
assert_eq!(
291+
last_element.as_ptr(),
292+
instance
293+
.elements
294+
.as_ptr()
295+
.wrapping_add(capacity as usize - 2)
296+
);
244297
}
245298
}
246299

src/containers/storage/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ mod test_utils {
8080

8181
impl<T> Storage<T> for Vec<MaybeUninit<T>> {
8282
fn new(capacity: u32) -> Self {
83-
Self::try_new(capacity).unwrap_or_else(|| panic!("failed to allocate for {capacity} elements"))
83+
Self::try_new(capacity)
84+
.unwrap_or_else(|| panic!("failed to allocate for {capacity} elements"))
8485
}
8586

8687
fn try_new(capacity: u32) -> Option<Self>

src/log/mw_log_fmt/builders.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ impl<'a> DebugStruct<'a> {
8080
pub fn finish(&mut self) -> Result {
8181
if self.has_fields {
8282
let empty_spec = FormatSpec::new();
83-
self.result = self.result.and_then(|_| self.writer.write_str(" }", &empty_spec));
83+
self.result = self
84+
.result
85+
.and_then(|_| self.writer.write_str(" }", &empty_spec));
8486
}
8587
self.result
8688
}
@@ -253,7 +255,10 @@ impl<'a> DebugSet<'a> {
253255

254256
/// Finishes output and returns any error encountered.
255257
pub fn finish(&mut self) -> Result {
256-
self.inner.result = self.inner.result.and_then(|_| self.inner.writer.write_str("}", &FormatSpec::new()));
258+
self.inner.result = self
259+
.inner
260+
.result
261+
.and_then(|_| self.inner.writer.write_str("}", &FormatSpec::new()));
257262
self.inner.result
258263
}
259264
}
@@ -323,7 +328,10 @@ impl<'a> DebugList<'a> {
323328

324329
/// Finishes output and returns any error encountered.
325330
pub fn finish(&mut self) -> Result {
326-
self.inner.result = self.inner.result.and_then(|_| self.inner.writer.write_str("]", &FormatSpec::new()));
331+
self.inner.result = self
332+
.inner
333+
.result
334+
.and_then(|_| self.inner.writer.write_str("]", &FormatSpec::new()));
327335
self.inner.result
328336
}
329337
}
@@ -420,7 +428,10 @@ impl<'a> DebugMap<'a> {
420428
F: FnOnce(Writer) -> Result,
421429
{
422430
self.result = self.result.and_then(|_| {
423-
assert!(self.has_key, "attempted to format a map value before its key");
431+
assert!(
432+
self.has_key,
433+
"attempted to format a map value before its key"
434+
);
424435
value_fmt(self.writer)?;
425436
self.has_key = false;
426437
Ok(())
@@ -446,7 +457,10 @@ impl<'a> DebugMap<'a> {
446457
/// Marks the map as non-exhaustive, indicating to the reader that there are some other entries that are not shown in the debug representation.
447458
pub fn finish_non_exhaustive(&mut self) -> Result {
448459
self.result = self.result.and_then(|_| {
449-
assert!(!self.has_key, "attempted to finish a map with a partial entry");
460+
assert!(
461+
!self.has_key,
462+
"attempted to finish a map with a partial entry"
463+
);
450464

451465
let empty_spec = FormatSpec::new();
452466
if self.has_fields {
@@ -466,7 +480,10 @@ impl<'a> DebugMap<'a> {
466480
/// Otherwise this method will panic.
467481
pub fn finish(&mut self) -> Result {
468482
self.result = self.result.and_then(|_| {
469-
assert!(!self.has_key, "attempted to finish a map with a partial entry");
483+
assert!(
484+
!self.has_key,
485+
"attempted to finish a map with a partial entry"
486+
);
470487
let empty_spec = FormatSpec::new();
471488
self.writer.write_str("}", &empty_spec)
472489
});
@@ -542,7 +559,9 @@ mod tests {
542559

543560
let mut writer = StringWriter::new();
544561
let spec = FormatSpec::new();
545-
let _ = DebugStruct::new(&mut writer, &spec, "X").finish().map_err(|_| panic!("failed to finish"));
562+
let _ = DebugStruct::new(&mut writer, &spec, "X")
563+
.finish()
564+
.map_err(|_| panic!("failed to finish"));
546565

547566
assert_eq!(writer.get(), format!("{:?}", v));
548567
}
@@ -594,7 +613,9 @@ mod tests {
594613
fn test_tuple_empty_finish() {
595614
let mut writer = StringWriter::new();
596615
let spec = FormatSpec::new();
597-
let _ = DebugTuple::new(&mut writer, &spec, "").finish().map_err(|_| panic!("failed to finish"));
616+
let _ = DebugTuple::new(&mut writer, &spec, "")
617+
.finish()
618+
.map_err(|_| panic!("failed to finish"));
598619

599620
assert_eq!(writer.get(), "");
600621
}
@@ -730,7 +751,10 @@ mod tests {
730751
.finish_non_exhaustive()
731752
.map_err(|_| panic!("failed to finish"));
732753

733-
assert_eq!(writer.get(), "{\"first\": 123, \"second\": 456, \"third\": 789, ..}");
754+
assert_eq!(
755+
writer.get(),
756+
"{\"first\": 123, \"second\": 456, \"third\": 789, ..}"
757+
);
734758
}
735759

736760
#[test]

src/log/mw_log_fmt/fmt.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ mod tests {
153153
Fragment::Placeholder(Placeholder::new(&-100i8, FormatSpec::new())),
154154
Fragment::Placeholder(Placeholder::new(&-1234i16, FormatSpec::new())),
155155
Fragment::Placeholder(Placeholder::new(&-123456i32, FormatSpec::new())),
156-
Fragment::Placeholder(Placeholder::new(&-1200000000000000000i64, FormatSpec::new())),
156+
Fragment::Placeholder(Placeholder::new(
157+
&-1200000000000000000i64,
158+
FormatSpec::new(),
159+
)),
157160
Fragment::Placeholder(Placeholder::new(&123u8, FormatSpec::new())),
158161
Fragment::Placeholder(Placeholder::new(&1234u16, FormatSpec::new())),
159162
Fragment::Placeholder(Placeholder::new(&123456u32, FormatSpec::new())),
@@ -192,7 +195,10 @@ mod tests {
192195
Fragment::Placeholder(Placeholder::new(&-100i8, FormatSpec::new())),
193196
Fragment::Placeholder(Placeholder::new(&-1234i16, FormatSpec::new())),
194197
Fragment::Placeholder(Placeholder::new(&-123456i32, FormatSpec::new())),
195-
Fragment::Placeholder(Placeholder::new(&-1200000000000000000i64, FormatSpec::new())),
198+
Fragment::Placeholder(Placeholder::new(
199+
&-1200000000000000000i64,
200+
FormatSpec::new(),
201+
)),
196202
Fragment::Placeholder(Placeholder::new(&123u8, FormatSpec::new())),
197203
Fragment::Placeholder(Placeholder::new(&1234u16, FormatSpec::new())),
198204
Fragment::Placeholder(Placeholder::new(&123456u32, FormatSpec::new())),

src/log/mw_log_fmt/fmt_impl_qm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ impl ScoreDebug for Path {
3535
}
3636

3737
f.write_str(valid, spec)?;
38-
f.write_str(core::char::REPLACEMENT_CHARACTER.encode_utf8(&mut [0; MAX_LEN_UTF8]), spec)?;
38+
f.write_str(
39+
core::char::REPLACEMENT_CHARACTER.encode_utf8(&mut [0; MAX_LEN_UTF8]),
40+
spec,
41+
)?;
3942
}
4043

4144
Ok(())

src/log/mw_log_fmt/fmt_spec.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,17 @@ mod tests {
291291
let width = Some(1234);
292292
let precision = Some(5);
293293

294-
let format_spec = FormatSpec::from_params(display_hint, fill, align, sign, alternate, zero_pad, debug_as_hex, width, precision);
294+
let format_spec = FormatSpec::from_params(
295+
display_hint,
296+
fill,
297+
align,
298+
sign,
299+
alternate,
300+
zero_pad,
301+
debug_as_hex,
302+
width,
303+
precision,
304+
);
295305

296306
assert!(format_spec.get_display_hint() == display_hint);
297307
assert!(format_spec.get_fill() == fill);

0 commit comments

Comments
 (0)