Struct WeakPtr

Source
pub struct WeakPtr<T: ?Sized> { /* private fields */ }
Expand description

Represents a pointer that only references the data it’s pointing to. Unlike OwnedPtr, dropping this pointer has no effect on the underlying data, this pointer can only immutably access the underlying data, and care must be taken to prevent this pointer from dangling.

This can be used in conjunction with OwnedPtr to form complex (and sometimes cyclic) data structures while still adhering to Rust’s ownership rules, and avoiding un-droppable memory cycles.

Implementations§

Source§

impl<T: ?Sized + 'static> WeakPtr<T>

Source§

impl<T: ?Sized> WeakPtr<T>

Source

pub fn is_initialized(&self) -> bool

Source

pub fn borrow(&self) -> &T

Source

pub fn downcast<U: 'static>(self) -> Result<WeakPtr<U>, WeakPtr<T>>

Source

pub fn from_inner(inner: (Option<*const T>, TypeId)) -> Self

Source

pub fn into_inner(self) -> (Option<*const T>, TypeId)

Trait Implementations§

Source§

impl<T: ?Sized> Clone for WeakPtr<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + ?Sized> Debug for WeakPtr<T>

Source§

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

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

impl<'a, T: ?Sized, U: ?Sized> PartialEq<&'a T> for WeakPtr<U>

Source§

fn eq(&self, other: &&'a T) -> bool

Returns true if this pointer and the provided reference both point to the same memory address.

Note that this may return true in some unintuitive/exotic cases:

  • If you have 2 references to the same piece of data, with different types, this will return true. For example, comparing String to dyn Display is valid, and will return true if they’re actually the same.
  • If one or both of the types are zero-sized: since it’s address may overlap with another piece of data.
  • Comparing the address of a struct to the address of its first field: these are conceptually different things, but both live at the same address, since structs are stored as a list of it’s fields.

See https://doc.rust-lang.org/std/ptr/fn.eq.html for more information. This function uses the same semantics.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a Node> for WeakPtr<Attribute>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Attribute>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Class>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Class>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<CustomType>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<CustomType>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Dictionary>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Dictionary>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Enum>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Enum>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Enumerator>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Enumerator>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Exception>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Exception>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Field>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Field>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Interface>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Interface>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Module>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Module>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Operation>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Operation>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Parameter>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Parameter>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Primitive>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Primitive>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<ResultType>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<ResultType>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Sequence>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Sequence>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<Struct>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<Struct>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<TypeAlias>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<TypeAlias>, Self::Error>

Attempts to unwrap a node to the specified concrete type.

If the Slice element held by the node is the specified type, this succeeds, and returns the unwrapped element in the requested container. Otherwise this method fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<dyn Entity>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<dyn Entity>, Self::Error>

Attempts to unwrap a node to a WeakPtr of a Slice Entity.

If the Slice element held by the node implements Entity, this succeeds and returns a typed pointer, otherwise this fails and returns an error message.

Source§

type Error = LookupError

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

impl<'a> TryFrom<&'a Node> for WeakPtr<dyn Type>

Source§

fn try_from(node: &'a Node) -> Result<WeakPtr<dyn Type>, Self::Error>

Attempts to unwrap a node to a WeakPtr of a Slice Type.

If the Slice element held by the node implements Type, this succeeds and returns a typed pointer, otherwise this fails and returns an error message.

Source§

type Error = LookupError

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

impl<T: ?Sized + Send> Send for WeakPtr<T>

Source§

impl<T: ?Sized + Sync> Sync for WeakPtr<T>

Auto Trait Implementations§

§

impl<T> Freeze for WeakPtr<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for WeakPtr<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Unpin for WeakPtr<T>
where T: ?Sized,

§

impl<T> UnwindSafe for WeakPtr<T>
where T: RefUnwindSafe + ?Sized,

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.