Skip to content

Commit

Permalink
Apply some lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazik24 committed Sep 20, 2020
1 parent f89ea44 commit 604de51
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ https://github.com/Kazik24/juggle)
https://crates.io/crates/juggle)
[![Documentation](https://docs.rs/juggle/badge.svg)](
https://docs.rs/juggle)
[![Rust version](https://img.shields.io/badge/Rust-1.46+-blueviolet.svg)](
https://docs.rs/juggle)

Async task switching for
[cooperative multitasking](https://en.wikipedia.org/wiki/Cooperative_multitasking)
Expand Down
2 changes: 1 addition & 1 deletion src/round/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<'futures> SchedulerAlgorithm<'futures> {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let mut buff = self.0.ctrl.registry.iter().map(|(k, _)| DebugTask(&self.0.ctrl.registry, Some(k)))
.filter(|t| {
match t.1.map(|id| t.0.get(id)).flatten() {
match t.1.and_then(|id| t.0.get(id)) {
Some(task) => task.is_suspended(),
None => false,
}
Expand Down
21 changes: 8 additions & 13 deletions src/round/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<'futures> WheelHandle<'futures> {
/// with fresh allocated `String` of that name. If you don't want to allocate temporary memory
/// for string use in such case, use [`with_name`](#method.with_name).
pub fn get_current_name(&self) -> Option<Cow<'static,str>> {
self.current().map(|id| self.get_name(id)).flatten()
self.current().and_then(|id| self.get_name(id))
}
/// Returns name of task with given id.
/// Returns `None` when:
Expand Down Expand Up @@ -373,12 +373,7 @@ impl Default for SpawnParams {

impl Debug for SpawnParams {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let s: Option<&str> = match &self.name {
TaskName::None => None,
TaskName::Dynamic(s) => Some(&s),
TaskName::Static(s) => Some(s),
};
if let Some(s) = s {
if let Some(s) = self.name.as_str() {
write!(f, "SpawnParams[name: \"{}\", suspended: {}]", s, self.suspended)
} else {
write!(f, "SpawnParams[suspended: {}]", self.suspended)
Expand All @@ -387,16 +382,16 @@ impl Debug for SpawnParams {
}

impl From<&'static str> for SpawnParams {
/// Works as [named](struct.SpawnParams.html#method.named) method.
fn from(v: &'static str) -> Self { SpawnParams::named(v) }
/// Works as [`named`](struct.SpawnParams.html#method.named) method.
fn from(v: &'static str) -> Self { Self::named(v) }
}

impl From<String> for SpawnParams {
/// Works as [dyn_named](struct.SpawnParams.html#method.dyn_named) method.
fn from(v: String) -> Self { SpawnParams::dyn_named(v) }
/// Works as [`dyn_named`](struct.SpawnParams.html#method.dyn_named) method.
fn from(v: String) -> Self { Self::dyn_named(v) }
}

impl From<bool> for SpawnParams {
/// Works as [suspended](struct.SpawnParams.html#method.suspended) method.
fn from(v: bool) -> Self { SpawnParams::suspended(v) }
/// Works as [`suspended`](struct.SpawnParams.html#method.suspended) method.
fn from(v: bool) -> Self { Self::suspended(v) }
}
2 changes: 1 addition & 1 deletion src/round/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'future> Registry<'future>{
//SAFETY: this is always safe cause iterators and borrows cannot resize slab and resizing
//operations such as insert or remove are not recursive (with exception for retain which
//updates count after iterating all tasks).
unsafe{ (&mut *self.slab.get()).len() }
unsafe{ (&*self.slab.get()).len() }
}

#[cfg(debug_assertions)]
Expand Down
4 changes: 4 additions & 0 deletions src/round/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl<'futures> Debug for LockedWheel<'futures> {
}
}

impl<'futures> Default for Wheel<'futures> {
fn default() -> Self { Self::new() }
}


impl<'futures> Future for Wheel<'futures> {
type Output = Result<(), SuspendError>;
Expand Down
9 changes: 4 additions & 5 deletions src/utils/chunk_slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ impl<I: ChunkSlabKey, T> ChunkSlab<I, T> {
}
}
pub fn iter(&self) -> impl Iterator<Item=(I, &T)> {
self.entries.iter().enumerate().map(|e| {
self.entries.iter().enumerate().flat_map(|e| {
let off = e.0 * CHUNK_SIZE;
e.1.data.iter().enumerate().map(move |e| (off + e.0, e.1))
}).flatten().filter_map(|e| {
}).filter_map(|e| {
match e.1 {
Entry::Full(v) => Some((I::from_index(e.0), v)),
Entry::Empty(_) => None,
}
})
}
pub fn iter_mut(&mut self) -> impl Iterator<Item=(I, &mut T)> {
self.entries.iter_mut().enumerate().map(|e| {
self.entries.iter_mut().enumerate().flat_map(|e| {
let off = e.0 * CHUNK_SIZE;
e.1.data.iter_mut().enumerate().map(move |e| (off + e.0, e.1))
}).flatten().filter_map(|e| {
}).filter_map(|e| {
match e.1 {
Entry::Full(v) => Some((I::from_index(e.0), v)),
Entry::Empty(_) => None,
Expand All @@ -150,7 +150,6 @@ impl<I: ChunkSlabKey, T> ChunkSlab<I, T> {

pub fn retain(&mut self,mut func: impl FnMut(I,&T)->bool){
for (ci,chunk) in self.entries.iter_mut().enumerate() {
let chunk: &mut Box<Chunk<I,T>> = chunk;
let offset = ci*CHUNK_SIZE;
for (i,val) in chunk.data.iter_mut().enumerate() {
if let Entry::Full(value) = val {
Expand Down

0 comments on commit 604de51

Please sign in to comment.