Skip to main content

Weak

Struct Weak 

Source
pub struct Weak<'scope, 'data, T: ManagedPriv<'scope, 'data>>(/* private fields */);
Expand description

A reference to Julia data that is not guaranteed to be rooted.

Managed types are generally guaranteed to wrap valid, rooted data. In some cases this guarantee is too strong. The garbage collector uses the roots as a starting point to determine what values can be reached, as long as you can guarantee a value is reachable it’s safe to use. Whenever data is not rooted jlrs returns a Weak. Because it’s not rooted it’s unsafe to use.

Implementations§

Source§

impl<'scope, 'data> Weak<'scope, 'data, TypedValue<'scope, 'data, AnyType>>

Source

pub fn from_value_ref(value_ref: WeakValue<'scope, 'data>) -> Self

Source§

impl<'scope, 'data, W: Managed<'scope, 'data>> Weak<'scope, 'data, W>

Source

pub unsafe fn root<'target, Tgt>( self, target: Tgt, ) -> Tgt::Data<'data, W::InScope<'target>>
where Tgt: Target<'target>,

Use target to root self.

Safety: The data pointed to by self must not have been freed by the GC yet.

Source

pub unsafe fn as_managed(self) -> W

Assume the reference still points to valid managed data and convert it to its managed type.

Safety: a reference is only guaranteed to be valid as long as it’s reachable from some GC root. If the reference is unreachable, the GC can free it. The GC can run whenever a safepoint is reached, this is typically the case when new Julia data is allocated.

Source

pub unsafe fn as_value(self) -> Value<'scope, 'data>

Assume the reference still points to valid managed data and convert it to a Value.

Safety: a reference is only guaranteed to be valid as long as it’s reachable from some GC root. If the reference is unreachable, the GC can free it. The GC can run whenever a safepoint is reached, this is typically the case when new Julia data is allocated.

Source

pub unsafe fn assume_owned(self) -> Weak<'scope, 'static, W::WithData<'static>>

Extends the 'data lifetime to 'static.

Safety: this method should only be used when no data borrowed from Rust is referenced by this Julia data.

Source

pub fn leak(self) -> Weak<'static, 'data, W::InScope<'static>>

Extends the 'scope lifetime to 'static, which allows this reference to Julia data to be leaked from a scope.

Safety: this method should only be called to return Julia data from a ccalled function or when storing Julia data in a foreign type.

Source

pub fn data_ptr(self) -> NonNull<c_void>

Returns a pointer to the data.

Trait Implementations§

Source§

impl CCallReturn for Weak<'static, 'static, DataType<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = DataType<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, DataType<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, Expr<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = Expr<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, Expr<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, Module<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = Module<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, Module<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, NamedTuple<'static, 'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = NamedTuple<'static, 'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, NamedTuple<'static, 'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, SimpleVector<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = SimpleVector<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, SimpleVector<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, JuliaString<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = JuliaString<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, JuliaString<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, Symbol<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = Symbol<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, Symbol<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, TypeName<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = TypeName<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, TypeName<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, TypeVar<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = TypeVar<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, TypeVar<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, Union<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = Union<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, Union<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, UnionAll<'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = UnionAll<'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, UnionAll<'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl CCallReturn for Weak<'static, 'static, Value<'static, 'static>>

Source§

type CCallReturnType = Value<'static, 'static>

Type constructor for the type returned by the ccalled function.
Source§

type FunctionReturnType = Value<'static, 'static>

Type constructor for the type returned by the generated Julia function.
Source§

type ReturnAs = Weak<'static, 'static, Value<'static, 'static>>

Type returned to Julia after calling Self::return_or_throw.
Source§

unsafe fn return_or_throw(self) -> Self::ReturnAs

Convert self to data that can be returned to Julia, or throw an exception. Read more
Source§

impl<'scope, 'data, T> Clone for Weak<'scope, 'data, T>
where T: ManagedPriv<'scope, 'data>,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'scope, 'data, T> Copy for Weak<'scope, 'data, T>
where T: ManagedPriv<'scope, 'data>,

Source§

impl<'scope, 'data, T: Managed<'scope, 'data>> Debug for Weak<'scope, 'data, T>

Source§

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

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

impl<'scope, 'data, T> ManagedWeak<'scope, 'data> for Weak<'scope, 'data, T>
where T: ManagedPriv<'scope, 'data>, Self: Copy + ValidLayout, Option<Self>: ValidField,

Source§

type Managed = T

The managed type wrapped by Weak.
Source§

fn into_weak(self) -> Weak<'scope, 'data, Self::Managed>

Source§

impl<T: Managed<'static, 'static>> Mark for Weak<'static, 'static, T>

Source§

unsafe fn mark<P: ForeignType>(&self, ptls: PTls, _parent: &P) -> usize

Mark all references to Julia data in self. Read more

Auto Trait Implementations§

§

impl<'scope, 'data, T> !Send for Weak<'scope, 'data, T>

§

impl<'scope, 'data, T> !Sync for Weak<'scope, 'data, T>

§

impl<'scope, 'data, T> Freeze for Weak<'scope, 'data, T>

§

impl<'scope, 'data, T> RefUnwindSafe for Weak<'scope, 'data, T>
where <T as ManagedPriv<'scope, 'data>>::Wraps: RefUnwindSafe,

§

impl<'scope, 'data, T> Unpin for Weak<'scope, 'data, T>

§

impl<'scope, 'data, T> UnsafeUnpin for Weak<'scope, 'data, T>

§

impl<'scope, 'data, T> UnwindSafe for Weak<'scope, 'data, T>
where <T as ManagedPriv<'scope, 'data>>::Wraps: RefUnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Compatible<T> for T
where T: ValidLayout,

Source§

impl<T> CompatibleCast for T
where T: ValidLayout,

Source§

type Inner = T

Source§

type Output<U> = U

Source§

fn compatible_cast<U>(&self) -> &<T as CompatibleCast>::Output<U>
where T: Compatible<U>,

Converts &Self to &U, &[Self] to &[U], and &[Self; N] to &[U; N].
Source§

fn compatible_cast_mut<U>(&mut self) -> &mut <T as CompatibleCast>::Output<U>
where T: Compatible<U>,

Converts &mut Self to &mut U, &mut [Self] to &mut [U], and &mut [Self; N] to &mut [U; N].
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.