Skip to content

Commit 031e11f

Browse files
committed
kernel: apply clippy suggestions
1 parent 32f4d1b commit 031e11f

File tree

10 files changed

+33
-31
lines changed

10 files changed

+33
-31
lines changed

kernel/src/application/application_manager.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl ApplicationManager {
6666
/// Create a new application manager from a chunk of ram
6767
pub fn new(ram: Ram, os_table_ptr: &'static mut Table) -> Self {
6868
Self {
69-
ram: ram,
69+
ram,
7070
target_cs: [0u8; 4],
7171
target_cs_idx: 0,
7272
service_fn: None,
@@ -111,21 +111,21 @@ impl ApplicationManager {
111111
fn digest_from_bytes(bytes: &[u8]) -> u32 {
112112
assert_eq!(bytes.len(), 4);
113113
// bytes arrive in reversed order
114-
let digest = ((u32::from(bytes[0])) << 24)
114+
115+
((u32::from(bytes[0])) << 24)
115116
| ((u32::from(bytes[1])) << 16)
116117
| ((u32::from(bytes[2])) << 8)
117-
| (u32::from(bytes[3]));
118-
digest
118+
| (u32::from(bytes[3]))
119119
}
120120

121121
/// Run the application
122122
pub fn execute(&mut self) -> Result<(), Error> {
123123
if !self.status.is_loaded {
124124
return Err(Error::NoApplication);
125125
}
126-
let setup_ptr = Self::fn_ptr_from_slice(&self.ram.as_ref()[..4]);
127-
let service_ptr = Self::fn_ptr_from_slice(&self.ram.as_ref()[4..8]);
128-
let input_ptr = Self::fn_ptr_from_slice(&self.ram.as_ref()[8..12]);
126+
let setup_ptr = Self::fn_ptr_from_slice(&self.ram.bytes()[..4]);
127+
let service_ptr = Self::fn_ptr_from_slice(&self.ram.bytes()[4..8]);
128+
let input_ptr = Self::fn_ptr_from_slice(&self.ram.bytes()[8..12]);
129129
let _result = unsafe {
130130
let setup: SetupFn = ::core::mem::transmute(setup_ptr);
131131
let service: ServiceFn = ::core::mem::transmute(service_ptr);
@@ -250,8 +250,8 @@ impl Ram {
250250
}
251251

252252
/// Get an immutable reference to the internal ram buffer
253-
pub fn as_ref(&self) -> &[u8] {
254-
&self.ram
253+
pub fn bytes(&self) -> &[u8] {
254+
self.ram
255255
}
256256

257257
pub fn as_slice(&self) -> &[u8] {

kernel/src/application/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub struct FrameBuffer {
3535

3636
impl FrameBuffer {
3737
/// Create a frame buffer from a pointer
38+
///
39+
/// # Safety
40+
///
41+
/// The pointer passed **must** but a unique pointer and not shared or aliased.
3842
pub unsafe fn new(ptr: *mut u8, len: usize, width: u8, height: u8) -> Self {
3943
Self {
4044
ptr,

kernel/src/application/states/clock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl State for ClockState {
7272
.ok();
7373
self.buffer.clear();
7474

75-
write!(self.buffer, "{:02}%", soc).unwrap();
75+
write!(self.buffer, "{soc:02}%").unwrap();
7676
Text::new(self.buffer.as_str(), Point::new(110, 12), style)
7777
.draw(display)
7878
.ok();

kernel/src/application/states/mwatch.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ use embedded_graphics::pixelcolor::Rgb565;
1111
use embedded_graphics::prelude::*;
1212
use embedded_graphics::text::{Alignment, Text};
1313

14+
#[derive(Default)]
1415
pub struct MWState {}
1516

16-
impl Default for MWState {
17-
fn default() -> Self {
18-
Self {}
19-
}
20-
}
17+
2118

2219
impl State for MWState {
2320
fn render(&mut self, _system: &mut System<impl Host>, display: &mut FrameBuffer) -> Option<Signal> {

kernel/src/application/states/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl State for NotificationState {
7878
system
7979
.nm
8080
.peek_notification(self.menu.selected() as usize, |notification| {
81-
self.body.render(display, &notification);
81+
self.body.render(display, notification);
8282
});
8383
}
8484
}

kernel/src/application/states/uop.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ use crate::{application::{states::prelude::*, FrameBuffer}, system::{System, inp
44

55
use embedded_graphics::{image::{Image, ImageRaw}, pixelcolor::{Rgb565, raw::LittleEndian}, prelude::{Point, OriginDimensions, Dimensions}, Drawable};
66

7+
#[derive(Default)]
78
pub struct UopState {}
89

9-
impl Default for UopState {
10-
fn default() -> Self {
11-
Self {
12-
13-
}
14-
}
15-
}
10+
1611

1712
impl State for UopState {
1813
fn render(&mut self, _system: &mut System<impl Host>, display: &mut FrameBuffer) -> Option<Signal> {

kernel/src/ingress/ingress_manager.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct IngressManager {
5353
impl IngressManager {
5454
/// Constructs a new IngressManager
5555
pub fn new() -> Self {
56-
IngressManager {
56+
Self {
5757
rb: Queue::new(),
5858
state: State::Init,
5959
hex_chars: [0u8; 2],
@@ -253,6 +253,12 @@ impl IngressManager {
253253
}
254254
}
255255

256+
impl Default for IngressManager {
257+
fn default() -> Self {
258+
Self::new()
259+
}
260+
}
261+
256262
#[cfg(test)]
257263
mod test {
258264
use super::*;

kernel/src/system/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct InputManager {
4343

4444
impl InputManager {
4545
/// Creates a new instance of the InputManager
46-
pub fn new() -> Self {
46+
pub const fn new() -> Self {
4747
Self {
4848
raw_vector: 0,
4949
last_vector: 0,

kernel/src/system/notification.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ impl Notification {
3131

3232
pub fn from_buffer(buffer: &Buffer, idxs: &[usize; 3]) -> Result<Notification, NotificationError> {
3333
Ok(Notification {
34-
section_indexes: idxs.clone(),
35-
inner: buffer.clone()
34+
section_indexes: *idxs,
35+
inner: *buffer
3636
})
3737
}
3838

@@ -60,7 +60,7 @@ pub struct NotificationManager {
6060
}
6161

6262
impl NotificationManager {
63-
pub fn new() -> NotificationManager {
63+
pub const fn new() -> NotificationManager {
6464
NotificationManager {
6565
pool: [Notification::default(); BUFF_COUNT],
6666
idx: 0,
@@ -73,7 +73,7 @@ impl NotificationManager {
7373
F: FnOnce(&Notification),
7474
{
7575
let notification = &self.pool[index];
76-
f(&notification);
76+
f(notification);
7777
}
7878

7979
pub fn idx(&self) -> usize {

kernel/src/system/syscall.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Syscall {
7474
}
7575
}
7676
// vals[0] // TODO day in week
77-
Ok(Date::from_calendar_date(vals[3], (vals[2] as u8).try_into().map_err(|_| Error::ParseError)?, vals[1] as u8).map_err(|_| Error::ParseError)?)
77+
Date::from_calendar_date(vals[3], (vals[2] as u8).try_into().map_err(|_| Error::ParseError)?, vals[1] as u8).map_err(|_| Error::ParseError)
7878
}
7979

8080
pub fn time_from_str(s: &str) -> Result<Time, Error> {
@@ -88,7 +88,7 @@ impl Syscall {
8888
}
8989
}
9090
}
91-
Ok(Time::from_hms(vals[0], vals[1], vals[2]).map_err(|_| Error::ParseError)?)
91+
Time::from_hms(vals[0], vals[1], vals[2]).map_err(|_| Error::ParseError)
9292
}
9393
}
9494

0 commit comments

Comments
 (0)