fix tests

This commit is contained in:
Evan Almloff committed 2024-01-02 15:19:01 -06:00
1 parent 73b7f450a5
commit b7c9817cf3
6 files changed
+52 -42

No files matched your search

+26 -13
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()
}