Fix clippy errors
This commit is contained in:
@@ -60,7 +60,7 @@ impl Writer {
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_font(&mut self, font: &'static Font) {
|
||||
pub const fn set_font(&mut self, font: &'static Font) {
|
||||
self.font = font;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ static WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
pub fn add_scancode(scancode: u8) {
|
||||
if let Some(queue) = KBD_QUEUE.get() {
|
||||
if let Err(_) = queue.push(scancode) {
|
||||
if queue.push(scancode).is_err() {
|
||||
println!("WARNING: scancode queue full; dropping keyboard input");
|
||||
} else {
|
||||
WAKER.wake();
|
||||
@@ -34,7 +34,13 @@ pub struct ScancodeStream {
|
||||
impl ScancodeStream {
|
||||
pub fn new() -> Self {
|
||||
KBD_QUEUE.call_once(|| ArrayQueue::new(5));
|
||||
ScancodeStream { _private: () }
|
||||
Self { _private: () }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ScancodeStream {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,15 +54,12 @@ impl Stream for ScancodeStream {
|
||||
return Poll::Ready(Some(scancode));
|
||||
}
|
||||
|
||||
WAKER.register(&cx.waker());
|
||||
WAKER.register(cx.waker());
|
||||
|
||||
match queue.pop() {
|
||||
Some(scancode) => {
|
||||
WAKER.take();
|
||||
Poll::Ready(Some(scancode))
|
||||
}
|
||||
None => Poll::Pending,
|
||||
}
|
||||
queue.pop().map_or(Poll::Pending, |scancode| {
|
||||
WAKER.take();
|
||||
Poll::Ready(Some(scancode))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ pub struct Task {
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
|
||||
Task {
|
||||
pub fn new(future: impl Future<Output = ()> + 'static) -> Self {
|
||||
Self {
|
||||
id: TaskId::new(),
|
||||
future: Box::pin(future),
|
||||
}
|
||||
@@ -31,7 +31,7 @@ struct TaskId(u64);
|
||||
impl TaskId {
|
||||
fn new() -> Self {
|
||||
static NEXT: AtomicU64 = AtomicU64::new(0);
|
||||
TaskId(NEXT.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
||||
Self(NEXT.fetch_add(1, core::sync::atomic::Ordering::Relaxed))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ pub struct Executor {
|
||||
|
||||
impl Executor {
|
||||
pub fn new() -> Self {
|
||||
Executor {
|
||||
Self {
|
||||
tasks: BTreeMap::new(),
|
||||
task_queue: Arc::new(ArrayQueue::new(100)),
|
||||
waker_cache: BTreeMap::new(),
|
||||
@@ -73,7 +73,7 @@ impl Executor {
|
||||
};
|
||||
let waker = waker_cache
|
||||
.entry(task_id)
|
||||
.or_insert_with(|| TaskWaker::new(task_id, task_queue.clone()));
|
||||
.or_insert_with(|| TaskWaker::new_waker(task_id, task_queue.clone()));
|
||||
let mut context = Context::from_waker(waker);
|
||||
match task.poll(&mut context) {
|
||||
Poll::Ready(()) => {
|
||||
@@ -103,6 +103,12 @@ impl Executor {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Executor {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
struct TaskWaker {
|
||||
task_id: TaskId,
|
||||
task_queue: Arc<ArrayQueue<TaskId>>,
|
||||
@@ -113,8 +119,8 @@ impl TaskWaker {
|
||||
self.task_queue.push(self.task_id).expect("task_queue full");
|
||||
}
|
||||
|
||||
fn new(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
|
||||
Waker::from(Arc::new(TaskWaker {
|
||||
fn new_waker(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
|
||||
Waker::from(Arc::new(Self {
|
||||
task_id,
|
||||
task_queue,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user