Skip to main content

OwnedPtr

Struct OwnedPtr 

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

Represents a pointer that owns the data it’s pointing to. When this pointer is dropped, it ensures the pointed to data is dropped as well.

This can be used in conjunction with WeakPtr 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> OwnedPtr<T>

Source

pub fn new(value: T) -> Self

Source§

impl<T: ?Sized> OwnedPtr<T>

Source

pub fn borrow(&self) -> &T

Source

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

§Safety

This function doesn’t use unsafe Rust, but is marked unsafe because the invoker must GUARANTEE there are no other references to the underlying data when calling this function.

The borrow checker can ensure that there are no other references through this OwnedPtr, but it’s possible to obtain a reference via WeakPtr::borrow instead. Because WeakPtr uses raw pointers, the borrow checker can’t reason about these accesses. So we have to enforce Rust’s borrow policy manually by ensuring this mutable borrow is the ONLY borrow.

Mutating the underlying data while another reference to it still exists, is undefined behavior. So ONLY call this function if you are CERTAIN that NO other references exist.

Source

pub fn downgrade(&self) -> WeakPtr<T>

Source

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

Source

pub fn from_inner(inner: (Box<T>, TypeId)) -> Self

Source

pub fn into_inner(self) -> (Box<T>, TypeId)

Trait Implementations§

Source§

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

Source§

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

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

impl From<OwnedPtr<Attribute>> for Node

Source§

fn from(ptr: OwnedPtr<Attribute>) -> Node

Wraps the OwnedPtr<Attribute> in a Node of the corresponding variant Node::Attribute.

Source§

impl From<OwnedPtr<CustomType>> for Node

Source§

fn from(ptr: OwnedPtr<CustomType>) -> Node

Wraps the OwnedPtr<CustomType> in a Node of the corresponding variant Node::CustomType.

Source§

impl From<OwnedPtr<Dictionary>> for Node

Source§

fn from(ptr: OwnedPtr<Dictionary>) -> Node

Wraps the OwnedPtr<Dictionary> in a Node of the corresponding variant Node::Dictionary.

Source§

impl From<OwnedPtr<Enum>> for Node

Source§

fn from(ptr: OwnedPtr<Enum>) -> Node

Wraps the OwnedPtr<Enum> in a Node of the corresponding variant Node::Enum.

Source§

impl From<OwnedPtr<Enumerator>> for Node

Source§

fn from(ptr: OwnedPtr<Enumerator>) -> Node

Wraps the OwnedPtr<Enumerator> in a Node of the corresponding variant Node::Enumerator.

Source§

impl From<OwnedPtr<Field>> for Node

Source§

fn from(ptr: OwnedPtr<Field>) -> Node

Wraps the OwnedPtr<Field> in a Node of the corresponding variant Node::Field.

Source§

impl From<OwnedPtr<Interface>> for Node

Source§

fn from(ptr: OwnedPtr<Interface>) -> Node

Wraps the OwnedPtr<Interface> in a Node of the corresponding variant Node::Interface.

Source§

impl From<OwnedPtr<Module>> for Node

Source§

fn from(ptr: OwnedPtr<Module>) -> Node

Wraps the OwnedPtr<Module> in a Node of the corresponding variant Node::Module.

Source§

impl From<OwnedPtr<Operation>> for Node

Source§

fn from(ptr: OwnedPtr<Operation>) -> Node

Wraps the OwnedPtr<Operation> in a Node of the corresponding variant Node::Operation.

Source§

impl From<OwnedPtr<Parameter>> for Node

Source§

fn from(ptr: OwnedPtr<Parameter>) -> Node

Wraps the OwnedPtr<Parameter> in a Node of the corresponding variant Node::Parameter.

Source§

impl From<OwnedPtr<ResultType>> for Node

Source§

fn from(ptr: OwnedPtr<ResultType>) -> Node

Wraps the OwnedPtr<ResultType> in a Node of the corresponding variant Node::ResultType.

Source§

impl From<OwnedPtr<Sequence>> for Node

Source§

fn from(ptr: OwnedPtr<Sequence>) -> Node

Wraps the OwnedPtr<Sequence> in a Node of the corresponding variant Node::Sequence.

Source§

impl From<OwnedPtr<Struct>> for Node

Source§

fn from(ptr: OwnedPtr<Struct>) -> Node

Wraps the OwnedPtr<Struct> in a Node of the corresponding variant Node::Struct.

Source§

impl From<OwnedPtr<TypeAlias>> for Node

Source§

fn from(ptr: OwnedPtr<TypeAlias>) -> Node

Wraps the OwnedPtr<TypeAlias> in a Node of the corresponding variant Node::TypeAlias.

Source§

impl<'a, T: ?Sized, U: ?Sized> PartialEq<&'a T> for OwnedPtr<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 (const: unstable) · 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 &'a OwnedPtr<Attribute>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<CustomType>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Dictionary>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Enum>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Enumerator>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Field>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Interface>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Module>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Operation>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Parameter>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Primitive>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<ResultType>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Sequence>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<Struct>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 &'a OwnedPtr<TypeAlias>

Source§

fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Attribute>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<CustomType>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Dictionary>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Enum>

Source§

fn try_from(node: &'a mut Node) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Enumerator>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Field>

Source§

fn try_from(node: &'a mut Node) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Interface>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Module>

Source§

fn try_from(node: &'a mut Node) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Operation>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Parameter>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Primitive>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<ResultType>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Sequence>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<Struct>

Source§

fn try_from(node: &'a mut Node) -> Result<&'a mut OwnedPtr<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 mut Node> for &'a mut OwnedPtr<TypeAlias>

Source§

fn try_from( node: &'a mut Node, ) -> Result<&'a mut OwnedPtr<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<T: ?Sized + Send> Send for OwnedPtr<T>

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for OwnedPtr<T>
where T: ?Sized,

§

impl<T> UnwindSafe for OwnedPtr<T>
where T: UnwindSafe + ?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> 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 = 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.