Skip to content

Commit d6fd400

Browse files
committed
zephyr: fmt update
Run `cargo fmt` to canonicalize the code. This is a lot of whitespace cleanups, so is likely to produce numerous conflicts with any pending PRs. But, the code should be better going forward. Signed-off-by: David Brown <[email protected]>
1 parent c2279d5 commit d6fd400

File tree

18 files changed

+147
-194
lines changed

18 files changed

+147
-194
lines changed

zephyr/src/align.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ impl_alignas!(1, 2, 4, 8, 16, 32, 64, 128, 256);
3434
/// member of the struct.
3535
#[repr(transparent)]
3636
pub struct AlignAs<const N: usize>([<AlignAsStruct as AlignAsTrait<N>>::Aligned; 0])
37-
where
37+
where
3838
AlignAsStruct: AlignAsTrait<N>;
3939

4040
impl<const N: usize> AlignAs<N>
41-
where AlignAsStruct: AlignAsTrait<N>
41+
where
42+
AlignAsStruct: AlignAsTrait<N>,
4243
{
4344
/// Construct a new AlignAs.
4445
///

zephyr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use core::panic::PanicInfo;
5353

5454
/// Override rust's panic. This simplistic initial version just hangs in a loop.
5555
#[panic_handler]
56-
fn panic(info :&PanicInfo) -> ! {
56+
fn panic(info: &PanicInfo) -> ! {
5757
#[cfg(CONFIG_PRINTK)]
5858
{
5959
printkln!("panic: {}", info);

zephyr/src/logging/impl_printk.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,11 @@ impl Log for PrintkLogger {
2424
// printing will be racy. Otherwise, the message will be broken into small chunks that are each
2525
// printed atomically.
2626
fn log(&self, record: &Record<'_>) {
27-
printkln!("{}:{}: {}",
28-
record.level(),
29-
record.target(),
30-
record.args());
27+
printkln!("{}:{}: {}", record.level(), record.target(), record.args());
3128
}
3229

3330
// Flush is not needed.
34-
fn flush(&self) {
35-
}
31+
fn flush(&self) {}
3632
}
3733

3834
static PRINTK_LOGGER: PrintkLogger = PrintkLogger;

zephyr/src/logging/impl_zlog.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ impl Log for ZlogLogger {
3535
// Zephyr doesn't have a separate trace, so fold that into debug.
3636
Level::Trace => raw::LOG_LEVEL_DBG,
3737
};
38-
let mut msg = format!("{}: {}",
39-
record.target(),
40-
record.args());
38+
let mut msg = format!("{}: {}", record.target(), record.args());
4139
// Append a null so this is a valid C string. This lets us avoid an additional allocation
4240
// and copying.
4341
msg.push('\x00');
@@ -47,8 +45,7 @@ impl Log for ZlogLogger {
4745
}
4846

4947
// Flush not needed.
50-
fn flush(&self) {
51-
}
48+
fn flush(&self) {}
5249
}
5350

5451
extern "C" {

zephyr/src/object.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ where
188188
KOBJ_UNINITIALIZED,
189189
KOBJ_INITING,
190190
Ordering::AcqRel,
191-
Ordering::Acquire)
192-
{
191+
Ordering::Acquire,
192+
) {
193193
return None;
194194
}
195195
let result = self.get_wrapped(args);
@@ -401,7 +401,7 @@ macro_rules! _kobj_stack {
401401
[$crate::sys::thread::RealStaticThreadStack<{$crate::sys::thread::stack_len($size)}>; $asize] =
402402
unsafe { ::core::mem::zeroed() };
403403

404-
$v static $name:
404+
$v static $name:
405405
[$crate::_export::KStaticThreadStack; $asize] =
406406
$crate::_export::KStaticThreadStack::new_from_array(&[< $name _REAL >]);
407407
}

zephyr/src/printk.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
//!
66
//! This uses the `k_str_out` syscall, which is part of printk to output to the console.
77
8-
use core::fmt::{
9-
Arguments,
10-
Result,
11-
Write,
12-
write,
13-
};
8+
use core::fmt::{write, Arguments, Result, Write};
149

1510
/// Print to Zephyr's console, without a newline.
1611
///

zephyr/src/sync.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,8 @@ pub use portable_atomic_util::Arc;
3030

3131
mod mutex;
3232

33-
pub use mutex::{
34-
Mutex,
35-
MutexGuard,
36-
Condvar,
37-
LockResult,
38-
TryLockResult,
39-
};
33+
pub use mutex::{Condvar, LockResult, Mutex, MutexGuard, TryLockResult};
4034

4135
mod spinmutex;
4236

43-
pub use spinmutex::{
44-
SpinMutex,
45-
SpinMutexGuard,
46-
};
37+
pub use spinmutex::{SpinMutex, SpinMutexGuard};

zephyr/src/sync/channel.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ pub fn unbounded_from<T>(queue: Queue) -> (Sender<T>, Receiver<T>) {
7070
flavor: SenderFlavor::Unbounded {
7171
queue: s,
7272
_phantom: PhantomData,
73-
}
73+
},
7474
};
7575
let r = Receiver {
7676
flavor: ReceiverFlavor::Unbounded {
7777
queue: r,
7878
_phantom: PhantomData,
79-
}
79+
},
8080
};
8181
(s, r)
8282
}
@@ -130,10 +130,7 @@ pub struct Message<T> {
130130

131131
impl<T> Message<T> {
132132
fn new(data: T) -> Message<T> {
133-
Message {
134-
_private: 0,
135-
data,
136-
}
133+
Message { _private: 0, data }
137134
}
138135
}
139136

@@ -155,7 +152,8 @@ impl<T> Sender<T> {
155152
/// For unbounded channels, this will perform an allocation (and always send immediately). For
156153
/// bounded channels, no allocation will be performed.
157154
pub fn send_timeout<D>(&self, msg: T, timeout: D) -> Result<(), SendError<T>>
158-
where D: Into<Timeout>,
155+
where
156+
D: Into<Timeout>,
159157
{
160158
match &self.flavor {
161159
SenderFlavor::Unbounded { queue, .. } => {
@@ -233,15 +231,11 @@ impl<T> Drop for Sender<T> {
233231
impl<T> Clone for Sender<T> {
234232
fn clone(&self) -> Self {
235233
let flavor = match &self.flavor {
236-
SenderFlavor::Unbounded { queue, .. } => {
237-
SenderFlavor::Unbounded {
238-
queue: queue.acquire(),
239-
_phantom: PhantomData,
240-
}
241-
}
242-
SenderFlavor::Bounded(chan) => {
243-
SenderFlavor::Bounded(chan.acquire())
244-
}
234+
SenderFlavor::Unbounded { queue, .. } => SenderFlavor::Unbounded {
235+
queue: queue.acquire(),
236+
_phantom: PhantomData,
237+
},
238+
SenderFlavor::Bounded(chan) => SenderFlavor::Bounded(chan.acquire()),
245239
};
246240

247241
Sender { flavor }
@@ -281,7 +275,8 @@ impl<T> Receiver<T> {
281275
/// operation can proceed or the operation times out.
282276
/// wake up and return an error.
283277
pub fn recv_timeout<D>(&self, timeout: D) -> Result<T, RecvError>
284-
where D: Into<Timeout>,
278+
where
279+
D: Into<Timeout>,
285280
{
286281
match &self.flavor {
287282
ReceiverFlavor::Unbounded { queue, .. } => {
@@ -369,15 +364,11 @@ impl<T> Drop for Receiver<T> {
369364
impl<T> Clone for Receiver<T> {
370365
fn clone(&self) -> Self {
371366
let flavor = match &self.flavor {
372-
ReceiverFlavor::Unbounded { queue, .. } => {
373-
ReceiverFlavor::Unbounded {
374-
queue: queue.acquire(),
375-
_phantom: PhantomData,
376-
}
377-
}
378-
ReceiverFlavor::Bounded(chan) => {
379-
ReceiverFlavor::Bounded(chan.acquire())
380-
}
367+
ReceiverFlavor::Unbounded { queue, .. } => ReceiverFlavor::Unbounded {
368+
queue: queue.acquire(),
369+
_phantom: PhantomData,
370+
},
371+
ReceiverFlavor::Bounded(chan) => ReceiverFlavor::Bounded(chan.acquire()),
381372
};
382373

383374
Receiver { flavor }
@@ -435,10 +426,8 @@ struct Bounded<T> {
435426
impl<T> Bounded<T> {
436427
fn new(cap: usize) -> Self {
437428
let slots: Box<[Slot<T>]> = (0..cap)
438-
.map(|_| {
439-
UnsafeCell::new(MaybeUninit::uninit())
440-
})
441-
.collect();
429+
.map(|_| UnsafeCell::new(MaybeUninit::uninit()))
430+
.collect();
442431
let slots = Box::into_pin(slots);
443432

444433
let free = Queue::new().unwrap();
@@ -452,7 +441,11 @@ impl<T> Bounded<T> {
452441
}
453442
}
454443

455-
Bounded { _slots: slots, free, chan }
444+
Bounded {
445+
_slots: slots,
446+
free,
447+
chan,
448+
}
456449
}
457450
}
458451

zephyr/src/sync/channel/counter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
44
// This file is taken from crossbeam-channels, with modifications to be nostd.
55

6-
76
extern crate alloc;
87

8+
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
99
use alloc::boxed::Box;
1010
use core::ops;
1111
use core::ptr::NonNull;
12-
use crate::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
1312

1413
/// Reference counter internals.
1514
struct Counter<C> {

zephyr/src/sync/mutex.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use core::{
1111
ops::{Deref, DerefMut},
1212
};
1313

14-
use crate::time::{Forever, NoWait};
1514
use crate::sys::sync as sys;
15+
use crate::time::{Forever, NoWait};
1616

1717
/// Until poisoning is implemented, mutexes never return an error, and we just get back the guard.
1818
pub type LockResult<Guard> = Result<Guard, ()>;
@@ -90,7 +90,10 @@ impl<T> Mutex<T> {
9090
/// sys Mutex will be taken by this structure. It is safe to share the underlying Mutex between
9191
/// different items, but without careful use, it is easy to deadlock, so it is not recommended.
9292
pub const fn new_from(t: T, raw_mutex: sys::Mutex) -> Mutex<T> {
93-
Mutex { inner: raw_mutex, data: UnsafeCell::new(t) }
93+
Mutex {
94+
inner: raw_mutex,
95+
data: UnsafeCell::new(t),
96+
}
9497
}
9598

9699
/// Construct a new Mutex, dynamically allocating the underlying sys Mutex.
@@ -114,9 +117,7 @@ impl<T: ?Sized> Mutex<T> {
114117
pub fn lock(&self) -> LockResult<MutexGuard<'_, T>> {
115118
// With `Forever`, should never return an error.
116119
self.inner.lock(Forever).unwrap();
117-
unsafe {
118-
Ok(MutexGuard::new(self))
119-
}
120+
unsafe { Ok(MutexGuard::new(self)) }
120121
}
121122

122123
/// Attempts to acquire this lock.
@@ -127,34 +128,29 @@ impl<T: ?Sized> Mutex<T> {
127128
/// This function does not block.
128129
pub fn try_lock(&self) -> TryLockResult<MutexGuard<'_, T>> {
129130
match self.inner.lock(NoWait) {
130-
Ok(()) => {
131-
unsafe {
132-
Ok(MutexGuard::new(self))
133-
}
134-
}
131+
Ok(()) => unsafe { Ok(MutexGuard::new(self)) },
135132
// TODO: It might be better to distinguish these errors, and only return the WouldBlock
136133
// if that is the corresponding error. But, the lock shouldn't fail in Zephyr.
137-
Err(_) => {
138-
Err(TryLockError::WouldBlock)
139-
}
134+
Err(_) => Err(TryLockError::WouldBlock),
140135
}
141136
}
142137
}
143138

144139
impl<'mutex, T: ?Sized> MutexGuard<'mutex, T> {
145140
unsafe fn new(lock: &'mutex Mutex<T>) -> MutexGuard<'mutex, T> {
146141
// poison todo
147-
MutexGuard { lock, _nosend: PhantomData }
142+
MutexGuard {
143+
lock,
144+
_nosend: PhantomData,
145+
}
148146
}
149147
}
150148

151149
impl<T: ?Sized> Deref for MutexGuard<'_, T> {
152150
type Target = T;
153151

154152
fn deref(&self) -> &T {
155-
unsafe {
156-
&*self.lock.data.get()
157-
}
153+
unsafe { &*self.lock.data.get() }
158154
}
159155
}
160156

0 commit comments

Comments
 (0)