Skip to main content

Owned

Struct Owned 

Source
pub struct Owned<L: LeanRepr> { /* private fields */ }
Expand description

A Lean value of the type named by L with one owner, which can move between threads and is still updated in place.

The objects of the value keep the reference counts of one thread, like those of a Local. That is sound because nothing else refers to them while the Owned is at rest: it is made from a Rust value or from a Lean, it cannot be cloned or shared (Send, not Sync), and Owned::with lends the value as a Local for the time of a closure only. A Local that outlives the closure is detected when the closure returns, and what it shares with the value is then marked as shared between threads, which costs the in-place updates of those objects and nothing else.

use leanfran_runtime::{List, Local, Owned};
use std::sync::Mutex;

let numbers = Mutex::new(Owned::<List<u32>>::new(vec![1, 2, 3]));
std::thread::scope(|s| {
    s.spawn(|| {
        let length = numbers.lock().unwrap().with(|list: Local<List<u32>>| {
            let length = list.get().len();
            (list, length)
        });
        assert_eq!(length, 3);
    });
});
ⓘ
let owned = leanfran_runtime::Owned::<u8>::new(1);
std::thread::scope(|s| {
    s.spawn(|| owned.get());
});

Implementations§

Source§

impl<L: LeanRepr> Owned<L>

Source

pub fn new(value: L::Value) -> Self

The handle of the Lean value of value.

Source

pub fn get(&self) -> L::Value

The Rust value of the handle.

Source

pub fn with<R>(&mut self, f: impl FnOnce(Local<L>) -> (Local<L>, R)) -> R

Lends the value to f as a Local and takes the Local that f returns as the new value. Passing the Local by value to a function of the local module of a generated module updates the value in place.

Every other Local made in f should be gone when f returns. If one is still alive (kept in a captured variable or in the result), or if f returns a Local it got from elsewhere, the new value is marked as shared between threads.

Source

pub fn share(self) -> Lean<L>

The handle that can be shared between threads.

Trait Implementations§

Source§

impl<L: LeanRepr> Debug for Owned<L>
where L::Value: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: LeanRepr> Drop for Owned<L>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<L: LeanRepr> From<Lean<L>> for Owned<L>

Source§

fn from(value: Lean<L>) -> Self

The shared value with one more owner. Its objects stay shared; the objects that functions build from it are owned.

Source§

impl<L: LeanRepr> Send for Owned<L>

Auto Trait Implementations§

§

impl<L> !Sync for Owned<L>

§

impl<L> Forget for Owned<L>

§

impl<L> Freeze for Owned<L>
where PhantomData<fn() -> L>: Freeze,

§

impl<L> Move for Owned<L>

§

impl<L> RefUnwindSafe for Owned<L>
where PhantomData<fn() -> L>: RefUnwindSafe,

§

impl<L> Unpin for Owned<L>
where PhantomData<fn() -> L>: Unpin,

§

impl<L> UnsafeUnpin for Owned<L>
where PhantomData<fn() -> L>: UnsafeUnpin,

§

impl<L> UnwindSafe for Owned<L>
where PhantomData<fn() -> L>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.