fix tests
This commit is contained in:
1 parent
73b7f450a5
commit
b7c9817cf3
6 files changed
+52
-42
No files matched your search
@@ -322,30 +322,30 @@ impl<T, S> Clone for GenerationalBox<T, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for types that can be mapped.
|
/// 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.
|
/// 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.
|
/// 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.
|
/// Try to map the value.
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&T) -> Option<&U>,
|
f: impl FnOnce(&T) -> Option<&U>,
|
||||||
) -> Option<Self::Mapped<U>>;
|
) -> Option<Self::Mapped<U>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for types that can be mapped mutably.
|
/// 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.
|
/// 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.
|
/// 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.
|
/// Try to map the value.
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
||||||
) -> Option<Self::Mapped<U>>;
|
) -> Option<Self::Mapped<U>>;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
fmt::{Debug, Display},
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
};
|
};
|
||||||
@@ -6,7 +7,7 @@ use std::{
|
|||||||
use crate::{Mappable, MappableMut};
|
use crate::{Mappable, MappableMut};
|
||||||
|
|
||||||
/// A reference to a value in a generational box.
|
/// 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,
|
inner: R,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[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> {
|
impl<T: ?Sized + 'static, R: Mappable<T>> Mappable<T> for GenerationalRef<T, R> {
|
||||||
type Mapped<U: 'static> = GenerationalRef<U, R::Mapped<U>>;
|
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 {
|
GenerationalRef {
|
||||||
inner: R::map(_self.inner, f),
|
inner: R::map(_self.inner, f),
|
||||||
phantom: PhantomData,
|
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,
|
_self: Self,
|
||||||
f: impl FnOnce(&T) -> Option<&U>,
|
f: impl FnOnce(&T) -> Option<&U>,
|
||||||
) -> Option<Self::Mapped<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;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@@ -90,7 +103,7 @@ impl Drop for GenerationalRefBorrowInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A mutable reference to a value in a generational box.
|
/// 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,
|
inner: W,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
#[cfg(any(debug_assertions, feature = "debug_borrows"))]
|
#[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> {
|
impl<T: ?Sized + 'static, W: MappableMut<T>> MappableMut<T> for GenerationalRefMut<T, W> {
|
||||||
type Mapped<U: 'static> = GenerationalRefMut<U, W::Mapped<U>>;
|
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 {
|
GenerationalRefMut {
|
||||||
inner: W::map(_self.inner, f),
|
inner: W::map(_self.inner, f),
|
||||||
phantom: PhantomData,
|
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,
|
_self: Self,
|
||||||
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
||||||
) -> Option<Self::Mapped<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;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
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 {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
self.inner.deref_mut()
|
self.inner.deref_mut()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,14 +48,14 @@ impl AnyStorage for SyncStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Mappable<T> for MappedRwLockReadGuard<'static, T> {
|
impl<T: ?Sized> Mappable<T> for MappedRwLockReadGuard<'static, T> {
|
||||||
type Mapped<U: 'static> = MappedRwLockReadGuard<'static, U>;
|
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)
|
MappedRwLockReadGuard::map(_self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&T) -> Option<&U>,
|
f: impl FnOnce(&T) -> Option<&U>,
|
||||||
) -> Option<Self::Mapped<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> {
|
impl<T: ?Sized> MappableMut<T> for MappedRwLockWriteGuard<'static, T> {
|
||||||
type Mapped<U: 'static> = MappedRwLockWriteGuard<'static, U>;
|
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)
|
MappedRwLockWriteGuard::map(_self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
||||||
) -> Option<Self::Mapped<U>> {
|
) -> Option<Self::Mapped<U>> {
|
||||||
|
|||||||
@@ -13,14 +13,14 @@ impl Default for UnsyncStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Mappable<T> for Ref<'static, T> {
|
impl<T: ?Sized> Mappable<T> for Ref<'static, T> {
|
||||||
type Mapped<U: 'static> = Ref<'static, U>;
|
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)
|
Ref::map(_self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&T) -> Option<&U>,
|
f: impl FnOnce(&T) -> Option<&U>,
|
||||||
) -> Option<Self::Mapped<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> {
|
impl<T: ?Sized> MappableMut<T> for RefMut<'static, T> {
|
||||||
type Mapped<U: 'static> = RefMut<'static, U>;
|
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)
|
RefMut::map(_self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_map<U: 'static>(
|
fn try_map<U: ?Sized + 'static>(
|
||||||
_self: Self,
|
_self: Self,
|
||||||
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
f: impl FnOnce(&mut T) -> Option<&mut U>,
|
||||||
) -> Option<Self::Mapped<U>> {
|
) -> Option<Self::Mapped<U>> {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ pub struct MappedSignal<U: 'static + ?Sized> {
|
|||||||
|
|
||||||
impl MappedSignal<()> {
|
impl MappedSignal<()> {
|
||||||
/// Create a new mapped signal.
|
/// 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>,
|
signal: Signal<T, S>,
|
||||||
mapping: impl Fn(&T) -> &U + 'static,
|
mapping: impl Fn(&T) -> &U + 'static,
|
||||||
) -> MappedSignal<
|
) -> MappedSignal<
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ fn create_signals_global() {
|
|||||||
let signal = create_without_cx();
|
let signal = create_without_cx();
|
||||||
let mapped = MappedSignal::new(signal, |v| v.as_bytes());
|
let mapped = MappedSignal::new(signal, |v| v.as_bytes());
|
||||||
|
|
||||||
render! {
|
render! { "{signal:?}", "{mapped:?}" }
|
||||||
"{signal:?}"
|
|
||||||
"{mapped:?}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _edits = dom.rebuild().santize();
|
let _edits = dom.rebuild().santize();
|
||||||
|
|||||||
Reference in new issue
Block a user