fix tests

This commit is contained in:
Evan Almloff 2024-01-02 15:19:01 -06:00
parent 73b7f450a5
commit b7c9817cf3
6 changed files with 52 additions and 42 deletions

View file

@ -322,30 +322,30 @@ impl<T, S> Clone for GenerationalBox<T, S> {
}
/// A trait for types that can be mapped.
pub trait Mappable<T>: Deref<Target = T> {
pub trait Mappable<T: ?Sized>: Deref<Target = T> {
/// The type after the mapping.
type Mapped<U: 'static>: Mappable<U> + Deref<Target = U>;
type Mapped<U: ?Sized + 'static>: Mappable<U> + Deref<Target = U>;
/// Map the value.
fn map<U: 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U>;
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U>;
/// Try to map the value.
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&T) -> Option<&U>,
) -> Option<Self::Mapped<U>>;
}
/// A trait for types that can be mapped mutably.
pub trait MappableMut<T>: DerefMut<Target = T> {
pub trait MappableMut<T: ?Sized>: DerefMut<Target = T> {
/// The type after the mapping.
type Mapped<U: 'static>: MappableMut<U> + DerefMut<Target = U>;
type Mapped<U: ?Sized + 'static>: MappableMut<U> + DerefMut<Target = U>;
/// Map the value.
fn map<U: 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U>;
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U>;
/// Try to map the value.
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&mut T) -> Option<&mut U>,
) -> Option<Self::Mapped<U>>;

View file

@ -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<T: 'static, R: Mappable<T>> {
pub struct GenerationalRef<T: ?Sized + 'static, R: Mappable<T>> {
inner: R,
phantom: PhantomData<T>,
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
@ -27,10 +28,10 @@ impl<T: 'static, R: Mappable<T>> GenerationalRef<T, R> {
}
}
impl<T: 'static, R: Mappable<T>> Mappable<T> for GenerationalRef<T, R> {
type Mapped<U: 'static> = GenerationalRef<U, R::Mapped<U>>;
impl<T: ?Sized + 'static, R: Mappable<T>> Mappable<T> for GenerationalRef<T, R> {
type Mapped<U: ?Sized + 'static> = GenerationalRef<U, R::Mapped<U>>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
GenerationalRef {
inner: R::map(_self.inner, f),
phantom: PhantomData,
@ -42,7 +43,7 @@ impl<T: 'static, R: Mappable<T>> Mappable<T> for GenerationalRef<T, R> {
}
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&T) -> Option<&U>,
) -> Option<Self::Mapped<U>> {
@ -64,7 +65,19 @@ impl<T: 'static, R: Mappable<T>> Mappable<T> for GenerationalRef<T, R> {
}
}
impl<T: 'static, R: Mappable<T>> Deref for GenerationalRef<T, R> {
impl<T: ?Sized + Debug, R: Mappable<T>> Debug for GenerationalRef<T, R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.deref().fmt(f)
}
}
impl<T: ?Sized + Display, R: Mappable<T>> Display for GenerationalRef<T, R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.inner.deref().fmt(f)
}
}
impl<T: ?Sized + 'static, R: Mappable<T>> Deref for GenerationalRef<T, R> {
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<T: 'static, W: MappableMut<T>> {
pub struct GenerationalRefMut<T: ?Sized + 'static, W: MappableMut<T>> {
inner: W,
phantom: PhantomData<T>,
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
@ -112,10 +125,10 @@ impl<T: 'static, R: MappableMut<T>> GenerationalRefMut<T, R> {
}
}
impl<T: 'static, W: MappableMut<T>> MappableMut<T> for GenerationalRefMut<T, W> {
type Mapped<U: 'static> = GenerationalRefMut<U, W::Mapped<U>>;
impl<T: ?Sized + 'static, W: MappableMut<T>> MappableMut<T> for GenerationalRefMut<T, W> {
type Mapped<U: ?Sized + 'static> = GenerationalRefMut<U, W::Mapped<U>>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
GenerationalRefMut {
inner: W::map(_self.inner, f),
phantom: PhantomData,
@ -124,7 +137,7 @@ impl<T: 'static, W: MappableMut<T>> MappableMut<T> for GenerationalRefMut<T, W>
}
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&mut T) -> Option<&mut U>,
) -> Option<Self::Mapped<U>> {
@ -143,7 +156,7 @@ impl<T: 'static, W: MappableMut<T>> MappableMut<T> for GenerationalRefMut<T, W>
}
}
impl<T: 'static, W: MappableMut<T>> Deref for GenerationalRefMut<T, W> {
impl<T: ?Sized + 'static, W: MappableMut<T>> Deref for GenerationalRefMut<T, W> {
type Target = T;
fn deref(&self) -> &Self::Target {
@ -151,7 +164,7 @@ impl<T: 'static, W: MappableMut<T>> Deref for GenerationalRefMut<T, W> {
}
}
impl<T: 'static, W: MappableMut<T>> DerefMut for GenerationalRefMut<T, W> {
impl<T: ?Sized + 'static, W: MappableMut<T>> DerefMut for GenerationalRefMut<T, W> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.inner.deref_mut()
}

View file

@ -48,14 +48,14 @@ impl AnyStorage for SyncStorage {
}
}
impl<T> Mappable<T> for MappedRwLockReadGuard<'static, T> {
type Mapped<U: 'static> = MappedRwLockReadGuard<'static, U>;
impl<T: ?Sized> Mappable<T> for MappedRwLockReadGuard<'static, T> {
type Mapped<U: ?Sized + 'static> = MappedRwLockReadGuard<'static, U>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
MappedRwLockReadGuard::map(_self, f)
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&T) -> Option<&U>,
) -> Option<Self::Mapped<U>> {
@ -63,14 +63,14 @@ impl<T> Mappable<T> for MappedRwLockReadGuard<'static, T> {
}
}
impl<T> MappableMut<T> for MappedRwLockWriteGuard<'static, T> {
type Mapped<U: 'static> = MappedRwLockWriteGuard<'static, U>;
impl<T: ?Sized> MappableMut<T> for MappedRwLockWriteGuard<'static, T> {
type Mapped<U: ?Sized + 'static> = MappedRwLockWriteGuard<'static, U>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
MappedRwLockWriteGuard::map(_self, f)
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&mut T) -> Option<&mut U>,
) -> Option<Self::Mapped<U>> {

View file

@ -13,14 +13,14 @@ impl Default for UnsyncStorage {
}
}
impl<T> Mappable<T> for Ref<'static, T> {
type Mapped<U: 'static> = Ref<'static, U>;
impl<T: ?Sized> Mappable<T> for Ref<'static, T> {
type Mapped<U: ?Sized + 'static> = Ref<'static, U>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&T) -> &U) -> Self::Mapped<U> {
Ref::map(_self, f)
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&T) -> Option<&U>,
) -> Option<Self::Mapped<U>> {
@ -28,14 +28,14 @@ impl<T> Mappable<T> for Ref<'static, T> {
}
}
impl<T> MappableMut<T> for RefMut<'static, T> {
type Mapped<U: 'static> = RefMut<'static, U>;
impl<T: ?Sized> MappableMut<T> for RefMut<'static, T> {
type Mapped<U: ?Sized + 'static> = RefMut<'static, U>;
fn map<U: 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
fn map<U: ?Sized + 'static>(_self: Self, f: impl FnOnce(&mut T) -> &mut U) -> Self::Mapped<U> {
RefMut::map(_self, f)
}
fn try_map<U: 'static>(
fn try_map<U: ?Sized + 'static>(
_self: Self,
f: impl FnOnce(&mut T) -> Option<&mut U>,
) -> Option<Self::Mapped<U>> {

View file

@ -15,7 +15,7 @@ pub struct MappedSignal<U: 'static + ?Sized> {
impl MappedSignal<()> {
/// Create a new mapped signal.
pub fn new<T, S: Storage<SignalData<T>>, U>(
pub fn new<T, S: Storage<SignalData<T>>, U: ?Sized>(
signal: Signal<T, S>,
mapping: impl Fn(&T) -> &U + 'static,
) -> MappedSignal<

View file

@ -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();