Skip to content

Commit

Permalink
LINTs, Rust 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kolarik committed Nov 28, 2024
1 parent 6ab14ef commit f8cdc83
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "futures-signals-ext"
version = "0.4.0"
authors = ["martin.kolarik@smartcontrol.cz"]
description = "Extension to futures-signals: MutableOption with combinators, spawning, predicate driven selections from SignalVec."
edition = "2021"
edition = "2024"
license = "MIT OR Apache-2.0"
repository = "https://github.com/martin-kolarik/futures-signals-ext"
homepage = "https://github.com/martin-kolarik/futures-signals-ext"
Expand Down
20 changes: 10 additions & 10 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'a, V: Copy> Value<'a, V> {
where
V: PartialEq,
{
if &self.value != &value {
if self.value != value {
self.value = value;
self.modified = true;
}
Expand All @@ -152,15 +152,15 @@ impl<'a, V: Copy> Value<'a, V> {
}
}

impl<'a, V: Copy> Deref for Value<'a, V> {
impl<V: Copy> Deref for Value<'_, V> {
type Target = V;

fn deref(&self) -> &V {
&self.value
}
}

impl<'a, V: Copy> Drop for Value<'a, V> {
impl<V: Copy> Drop for Value<'_, V> {
fn drop(&mut self) {
if self.modified
&& let Some(mut entry) = self.entry.take()
Expand Down Expand Up @@ -301,7 +301,7 @@ impl<'a, V: Clone> ValueCloned<'a, V> {
where
V: PartialEq,
{
if &self.value != &value {
if self.value != value {
self.value = value;
self.modified = true;
}
Expand All @@ -320,15 +320,15 @@ impl<'a, V: Clone> ValueCloned<'a, V> {
}
}

impl<'a, V: Clone> Deref for ValueCloned<'a, V> {
impl<V: Clone> Deref for ValueCloned<'_, V> {
type Target = V;

fn deref(&self) -> &V {
&self.value
}
}

impl<'a, V: Clone> Drop for ValueCloned<'a, V> {
impl<V: Clone> Drop for ValueCloned<'_, V> {
fn drop(&mut self) {
if self.modified
&& let Some(mut entry) = self.entry.take()
Expand All @@ -339,17 +339,17 @@ impl<'a, V: Clone> Drop for ValueCloned<'a, V> {
}

pub trait MutableVecEntry<V> {
fn entry<'a, F>(&'a self, f: F) -> Entry<'a, V>
fn entry<F>(&self, f: F) -> Entry<V>
where
F: FnMut(&V) -> bool;

fn entry_cloned<'a, F>(&'a self, f: F) -> EntryCloned<'a, V>
fn entry_cloned<F>(&self, f: F) -> EntryCloned<V>
where
F: FnMut(&V) -> bool;
}

impl<V> MutableVecEntry<V> for MutableVec<V> {
fn entry<'a, F>(&'a self, f: F) -> Entry<'a, V>
fn entry<F>(&self, f: F) -> Entry<V>
where
F: FnMut(&V) -> bool,
{
Expand All @@ -358,7 +358,7 @@ impl<V> MutableVecEntry<V> for MutableVec<V> {
Entry { key, lock }
}

fn entry_cloned<'a, F>(&'a self, f: F) -> EntryCloned<'a, V>
fn entry_cloned<F>(&self, f: F) -> EntryCloned<V>
where
F: FnMut(&V) -> bool,
{
Expand Down
35 changes: 25 additions & 10 deletions src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,49 @@ impl<T> MutableOption<T> {
self.0.lock_ref().as_ref().and_then(f)
}

pub fn signal_some_default(&self) -> impl Signal<Item = T>
pub fn signal_some_default(&self) -> impl Signal<Item = T> + use<T>
where
T: Default + Copy,
{
self.signal_map_some_default(|v| *v)
}

pub fn signal_cloned_some_default(&self) -> impl Signal<Item = T>
pub fn signal_cloned_some_default(&self) -> impl Signal<Item = T> + use<T>
where
T: Default + Clone,
{
self.signal_map_some_default(|v| v.clone())
}

pub fn signal_map<F, U>(&self, mut f: F) -> impl Signal<Item = Option<U>>
pub fn signal_map<F, U>(&self, mut f: F) -> impl Signal<Item = Option<U>> + use<T, F, U>
where
F: FnMut(Option<&T>) -> Option<U>,
{
self.0.signal_ref(move |v| f(v.as_ref()))
}

pub fn signal_map_some<F, U>(&self, mut f: F) -> impl Signal<Item = Option<U>>
pub fn signal_map_some<F, U>(&self, mut f: F) -> impl Signal<Item = Option<U>> + use<T, F, U>
where
F: FnMut(&T) -> U,
{
self.0.signal_ref(move |v| v.as_ref().map(&mut f))
}

pub fn signal_and_then_some<F, U>(&self, mut f: F) -> impl Signal<Item = Option<U>>
pub fn signal_and_then_some<F, U>(
&self,
mut f: F,
) -> impl Signal<Item = Option<U>> + use<T, F, U>
where
F: FnMut(&T) -> Option<U>,
{
self.0.signal_ref(move |v| v.as_ref().and_then(&mut f))
}

pub fn signal_and_then_some_or<F, U>(&self, mut f: F, default: U) -> impl Signal<Item = U>
pub fn signal_and_then_some_or<F, U>(
&self,
mut f: F,
default: U,
) -> impl Signal<Item = U> + use<T, F, U>
where
F: FnMut(&T) -> Option<U>,
U: Clone,
Expand All @@ -147,7 +154,7 @@ impl<T> MutableOption<T> {
&self,
mut f: F,
default: D,
) -> impl Signal<Item = U>
) -> impl Signal<Item = U> + use<T, F, D, U>
where
F: FnMut(&T) -> Option<U>,
D: FnOnce() -> U + Clone,
Expand All @@ -156,7 +163,11 @@ impl<T> MutableOption<T> {
.signal_ref(move |v| v.as_ref().and_then(&mut f).unwrap_or_else(default.clone()))
}

pub fn signal_map_some_or<F, U>(&self, mut f: F, default: U) -> impl Signal<Item = U>
pub fn signal_map_some_or<F, U>(
&self,
mut f: F,
default: U,
) -> impl Signal<Item = U> + use<T, F, U>
where
F: FnMut(&T) -> U,
U: Clone,
Expand All @@ -165,7 +176,11 @@ impl<T> MutableOption<T> {
.signal_ref(move |v| v.as_ref().map(&mut f).unwrap_or(default.clone()))
}

pub fn signal_map_some_or_else<F, D, U>(&self, mut f: F, default: D) -> impl Signal<Item = U>
pub fn signal_map_some_or_else<F, D, U>(
&self,
mut f: F,
default: D,
) -> impl Signal<Item = U> + use<T, F, D, U>
where
F: FnMut(&T) -> U,
D: FnOnce() -> U + Clone,
Expand All @@ -174,7 +189,7 @@ impl<T> MutableOption<T> {
.signal_ref(move |v| v.as_ref().map(&mut f).unwrap_or_else(default.clone()))
}

pub fn signal_map_some_default<F, U>(&self, mut f: F) -> impl Signal<Item = U>
pub fn signal_map_some_default<F, U>(&self, mut f: F) -> impl Signal<Item = U> + use<T, F, U>
where
F: FnMut(&T) -> U,
U: Default,
Expand Down
6 changes: 3 additions & 3 deletions src/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub trait SignalVecSpawn<A> {

#[cfg(not(target_os = "unknown"))]
mod os {
use std::future::{ready, Future};
use std::future::{Future, ready};

use futures_signals::{
signal::{Signal, SignalExt},
Expand Down Expand Up @@ -95,7 +95,7 @@ mod os {
F: Fn(A) -> W + 'static,
W: Future<Output = ()> + 'static,
{
artwrap::spawn_local(self.for_each(move |new| f(new)));
artwrap::spawn_local(self.for_each(f));
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ mod os {

#[cfg(all(target_arch = "wasm32", feature = "spawn-local"))]
mod wasm {
use std::future::{ready, Future};
use std::future::{Future, ready};

use futures_signals::{
signal::{Signal, SignalExt},
Expand Down

0 comments on commit f8cdc83

Please sign in to comment.