From c31b7712a2daf8bafbf19f4b4af695ca33831aa1 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 25 Jan 2023 09:03:17 -0300 Subject: Deprecate for selfref --- Cargo.toml | 7 ++-- README.md | 8 ++-- src/lib.rs | 127 ++++--------------------------------------------------------- 3 files changed, 14 insertions(+), 128 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9444bf9..1ecf01d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "srce" -version = "0.1.0" +version = "0.1.1" authors = ["SoniEx2 "] edition = "2021" description = "Self-Ref Cell Environments" @@ -12,9 +12,8 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -selfref = "0.4" -qcell = {version="0.5.2", default-features=false, features=["generativity"]} -generativity = "1.0.1" +selfref = {version="0.4.1", features=["qcell"]} [dev-dependencies] selfref = {features=["alloc"]} +qcell = "0.5.2" diff --git a/README.md b/README.md index 5decae9..8e7f54b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Self-Ref Cell Environment (SRCE) -SRCE is a way to open and close an `LCellOwner`, thus allowing the use of -`LCell` with tokio. +**Deprecated:** This crate is deprecated in favor of `selfref`'s `srce` module. +It was an experiment that's now integrated into `selfref`. -It is based on `qcell` and `selfref`. - -This crate has not been audited for soundness at this time. +It now merely re-exports the `srce` module. diff --git a/src/lib.rs b/src/lib.rs index 3004718..9862537 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,126 +4,15 @@ // // SPDX-License-Identifier: MIT OR Apache-2.0 -#![cfg_attr(not(test), no_std)] +#![no_std] -//! SRCE is a way to open and close an `LCellOwner`, thus allowing the use of -//! `LCell` with tokio. +//! **Deprecated:** This crate is deprecated in favor of `selfref`'s `srce` +//! module. You can use that one directly. This merely re-exports that module. //! -//! It is based on `qcell` and `selfref`. +//! SRCE is a way to open and close an `LCellOwner`. This provides the full +//! expressive power of `selfref`, with the ability to use zeroish-cost +//! `LCell`s in the struct. //! -//! This crate has not been audited for soundness at this time. +//! Refer to [`selfref::srce`] for more details. -use qcell::LCellOwner; -use selfref::{Builder, Holder, Opaque, OperateIn}; - -use core::pin::Pin; - -/// A self-referential environment of `LCell`s, with zero runtime cost. -pub struct LCellEnvironment<'k, T: Opaque + 'k> { - inner: Holder<'k, T>, -} - -impl<'k, T> LCellEnvironment<'k, T> where T: Opaque { - /// Creates a new `LCellEnvironment`. - /// - /// Works exactly like [`Holder::new_with`]. - pub fn new_with(f: F) -> Self - where - F: for<'a> FnOnce(&mut Builder<'a, T>), - T::Kind<'k>: Sized, - { - Self { - inner: Holder::new_with(f) - } - } -} - -impl<'k, T> LCellEnvironment<'k, T> where T: Opaque { - /// Opens this LCellEnvironment for reading and writing (mutable). - pub fn open_rw<'i, F, R>(self: Pin<&'i mut Self>, f: F) -> R - where - F: for<'a, 'id> FnOnce(&'a mut LCellOwner<'id>, OperateIn<'id, T>) -> R, - { - unsafe { - self.map_unchecked_mut(|this| &mut this.inner) - }.into_ref().operate_in(|env| { - // SAFETY? we're actually unsure if this is sound! - // the LCellOwner is owned by us, and the borrow given to the - // closure is mutable if we're mutable, and shared if we're shared. - let guard = unsafe { - generativity::Guard::new(generativity::Id::new()) - }; - f(&mut LCellOwner::new(guard), env) - }) - } - - /// Opens this LCellEnvironment for reading only (shared). - pub fn open_ro<'i, F, R>(self: Pin<&'i Self>, f: F) -> R - where - F: for<'a, 'id> FnOnce(&'a LCellOwner<'id>, OperateIn<'id, T>) -> R, - { - unsafe { - self.map_unchecked(|this| &this.inner) - }.operate_in(|env| { - // SAFETY? we're actually unsure if this is sound! - // the LCellOwner is owned by us, and the borrow given to the - // closure is mutable if we're mutable, and shared if we're shared. - let guard = unsafe { - generativity::Guard::new(generativity::Id::new()) - }; - f(&LCellOwner::new(guard), env) - }) - } -} - -#[test] -fn test() { - use core::cell::Cell; - use core::marker::PhantomData; - use qcell::LCell; - - trait Foo { - fn update(&mut self); - } - trait Bar { - fn get(&self) -> String; - } - struct MyThing; - impl Foo for MyThing { - fn update(&mut self) { - println!("hello world!"); - } - } - impl Bar for MyThing { - fn get(&self) -> String { - return String::from("hello"); - } - } - struct IntrusiveLCell<'a, T: ?Sized> { - y: Cell>>, - x: LCell<'a, T>, - } - struct IntrusiveLCellKey(PhantomData); - selfref::opaque! { - impl[T: ?Sized] Opaque for IntrusiveLCellKey { - type Kind<'this> = IntrusiveLCell<'this, T>; - } - } - let mut holder = Box::pin( - LCellEnvironment::>::new_with(|b| b.build( - IntrusiveLCell { - x: LCell::new(MyThing), - y: Cell::new(None), - } - )) - ); - - - holder.as_mut().open_rw(|owner, x| { - x.y.set(Some(&x.get_ref().x)); - owner.rw(&x.x).update(); - println!("{}", owner.ro(x.y.get().unwrap()).get()); - }); - - let mut holder_dyn: Pin>>> = holder; -} +pub use selfref::srce::*; -- cgit v1.2.3