~jplatte/oref

8691aa48288ca547f08fc3a62121ff6c0dabd89e — Jonas Platte 9 months ago 9f9d60d
Add more GetHandle types
2 files changed, 34 insertions(+), 9 deletions(-)

M src/handle.rs
M src/lib.rs
M src/handle.rs => src/handle.rs +31 -6
@@ 1,15 1,40 @@
use std::marker::PhantomData;

use stable_deref_trait::StableDeref;
use std::{
    cell::{Ref, RefMut},
    marker::PhantomData,
};

pub trait GetHandle {
    type Handle<'a>;
}

pub struct GetDeref<T: StableDeref> {
pub struct GetRef<T: ?Sized> {
    _phantom: PhantomData<T>,
}

impl<T: ?Sized + 'static> GetHandle for GetRef<T> {
    type Handle<'a> = &'a T;
}

pub struct GetMutRef<T: ?Sized> {
    _phantom: PhantomData<T>,
}

impl<T: ?Sized + 'static> GetHandle for GetMutRef<T> {
    type Handle<'a> = &'a mut T;
}

pub struct GetCellRef<T: ?Sized> {
    _phantom: PhantomData<T>,
}

impl<T: ?Sized + 'static> GetHandle for GetCellRef<T> {
    type Handle<'a> = Ref<'a, T>;
}

pub struct GetCellRefMut<T: ?Sized> {
    _phantom: PhantomData<T>,
}

impl<T: StableDeref + 'static> GetHandle for GetDeref<T> {
    type Handle<'a> = &'a T::Target;
impl<T: ?Sized + 'static> GetHandle for GetCellRefMut<T> {
    type Handle<'a> = RefMut<'a, T>;
}

M src/lib.rs => src/lib.rs +3 -3
@@ 2,9 2,9 @@

use stable_deref_trait::StableDeref;

mod handle;
pub mod handle;

use handle::{GetDeref, GetHandle};
use handle::{GetHandle, GetRef};

pub struct ORef<T, H>
where


@@ 16,7 16,7 @@ where
    handle: H::Handle<'static>,
}

impl<T> ORef<T, GetDeref<T>>
impl<T> ORef<T, GetRef<T::Target>>
where
    T: StableDeref + 'static,
{