diff --git a/packages/generational-box/src/lib.rs b/packages/generational-box/src/lib.rs index b8fdee94b..4bbe06d8a 100644 --- a/packages/generational-box/src/lib.rs +++ b/packages/generational-box/src/lib.rs @@ -322,30 +322,30 @@ impl Clone for GenerationalBox { } /// A trait for types that can be mapped. -pub trait Mappable: Deref { +pub trait Mappable: Deref { /// The type after the mapping. - type Mapped: Mappable + Deref; + type Mapped: Mappable + Deref; /// Map the value. - fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped; + fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped; /// Try to map the value. - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&T) -> Option<&U>, ) -> Option>; } /// A trait for types that can be mapped mutably. -pub trait MappableMut: DerefMut { +pub trait MappableMut: DerefMut { /// The type after the mapping. - type Mapped: MappableMut + DerefMut; + type Mapped: MappableMut + DerefMut; /// Map the value. - fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped; + fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped; /// Try to map the value. - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&mut T) -> Option<&mut U>, ) -> Option>; diff --git a/packages/generational-box/src/references.rs b/packages/generational-box/src/references.rs index c2f52946c..115babf7a 100644 --- a/packages/generational-box/src/references.rs +++ b/packages/generational-box/src/references.rs @@ -1,4 +1,5 @@ use std::{ + fmt::{Debug, Display}, marker::PhantomData, ops::{Deref, DerefMut}, }; @@ -6,7 +7,7 @@ use std::{ use crate::{Mappable, MappableMut}; /// A reference to a value in a generational box. -pub struct GenerationalRef> { +pub struct GenerationalRef> { inner: R, phantom: PhantomData, #[cfg(any(debug_assertions, feature = "debug_borrows"))] @@ -27,10 +28,10 @@ impl> GenerationalRef { } } -impl> Mappable for GenerationalRef { - type Mapped = GenerationalRef>; +impl> Mappable for GenerationalRef { + type Mapped = GenerationalRef>; - fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { GenerationalRef { inner: R::map(_self.inner, f), phantom: PhantomData, @@ -42,7 +43,7 @@ impl> Mappable for GenerationalRef { } } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&T) -> Option<&U>, ) -> Option> { @@ -64,7 +65,19 @@ impl> Mappable for GenerationalRef { } } -impl> Deref for GenerationalRef { +impl> Debug for GenerationalRef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.inner.deref().fmt(f) + } +} + +impl> Display for GenerationalRef { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.inner.deref().fmt(f) + } +} + +impl> Deref for GenerationalRef { type Target = T; fn deref(&self) -> &Self::Target { @@ -90,7 +103,7 @@ impl Drop for GenerationalRefBorrowInfo { } /// A mutable reference to a value in a generational box. -pub struct GenerationalRefMut> { +pub struct GenerationalRefMut> { inner: W, phantom: PhantomData, #[cfg(any(debug_assertions, feature = "debug_borrows"))] @@ -112,10 +125,10 @@ impl> GenerationalRefMut { } } -impl> MappableMut for GenerationalRefMut { - type Mapped = GenerationalRefMut>; +impl> MappableMut for GenerationalRefMut { + type Mapped = GenerationalRefMut>; - fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { GenerationalRefMut { inner: W::map(_self.inner, f), phantom: PhantomData, @@ -124,7 +137,7 @@ impl> MappableMut for GenerationalRefMut } } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&mut T) -> Option<&mut U>, ) -> Option> { @@ -143,7 +156,7 @@ impl> MappableMut for GenerationalRefMut } } -impl> Deref for GenerationalRefMut { +impl> Deref for GenerationalRefMut { type Target = T; fn deref(&self) -> &Self::Target { @@ -151,7 +164,7 @@ impl> Deref for GenerationalRefMut { } } -impl> DerefMut for GenerationalRefMut { +impl> DerefMut for GenerationalRefMut { fn deref_mut(&mut self) -> &mut Self::Target { self.inner.deref_mut() } diff --git a/packages/generational-box/src/sync.rs b/packages/generational-box/src/sync.rs index e11c17418..7d940278f 100644 --- a/packages/generational-box/src/sync.rs +++ b/packages/generational-box/src/sync.rs @@ -48,14 +48,14 @@ impl AnyStorage for SyncStorage { } } -impl Mappable for MappedRwLockReadGuard<'static, T> { - type Mapped = MappedRwLockReadGuard<'static, U>; +impl Mappable for MappedRwLockReadGuard<'static, T> { + type Mapped = MappedRwLockReadGuard<'static, U>; - fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { MappedRwLockReadGuard::map(_self, f) } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&T) -> Option<&U>, ) -> Option> { @@ -63,14 +63,14 @@ impl Mappable for MappedRwLockReadGuard<'static, T> { } } -impl MappableMut for MappedRwLockWriteGuard<'static, T> { - type Mapped = MappedRwLockWriteGuard<'static, U>; +impl MappableMut for MappedRwLockWriteGuard<'static, T> { + type Mapped = MappedRwLockWriteGuard<'static, U>; - fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { MappedRwLockWriteGuard::map(_self, f) } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&mut T) -> Option<&mut U>, ) -> Option> { diff --git a/packages/generational-box/src/unsync.rs b/packages/generational-box/src/unsync.rs index dac9967f0..d941dd00b 100644 --- a/packages/generational-box/src/unsync.rs +++ b/packages/generational-box/src/unsync.rs @@ -13,14 +13,14 @@ impl Default for UnsyncStorage { } } -impl Mappable for Ref<'static, T> { - type Mapped = Ref<'static, U>; +impl Mappable for Ref<'static, T> { + type Mapped = Ref<'static, U>; - fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped { Ref::map(_self, f) } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&T) -> Option<&U>, ) -> Option> { @@ -28,14 +28,14 @@ impl Mappable for Ref<'static, T> { } } -impl MappableMut for RefMut<'static, T> { - type Mapped = RefMut<'static, U>; +impl MappableMut for RefMut<'static, T> { + type Mapped = RefMut<'static, U>; - fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { + fn map(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped { RefMut::map(_self, f) } - fn try_map( + fn try_map( _self: Self, f: impl FnOnce(&mut T) -> Option<&mut U>, ) -> Option> { diff --git a/packages/signals/src/map.rs b/packages/signals/src/map.rs index 6c02b8553..b7093e27b 100644 --- a/packages/signals/src/map.rs +++ b/packages/signals/src/map.rs @@ -15,7 +15,7 @@ pub struct MappedSignal { impl MappedSignal<()> { /// Create a new mapped signal. - pub fn new>, U>( + pub fn new>, U: ?Sized>( signal: Signal, mapping: impl Fn(&T) -> &U + 'static, ) -> MappedSignal< diff --git a/packages/signals/tests/map.rs b/packages/signals/tests/map.rs index e93d2fed0..bea13009a 100644 --- a/packages/signals/tests/map.rs +++ b/packages/signals/tests/map.rs @@ -18,10 +18,7 @@ fn create_signals_global() { let signal = create_without_cx(); let mapped = MappedSignal::new(signal, |v| v.as_bytes()); - render! { - "{signal:?}" - "{mapped:?}" - } + render! { "{signal:?}", "{mapped:?}" } } let _edits = dom.rebuild().santize();