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> OwnedPtr<T>
impl<T: ?Sized> OwnedPtr<T>
pub fn borrow(&self) -> &T
Sourcepub unsafe fn borrow_mut(&mut self) -> &mut T
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.
pub fn downgrade(&self) -> WeakPtr<T>
pub fn downcast<U: 'static>(self) -> Result<OwnedPtr<U>, OwnedPtr<T>>
pub fn from_inner(inner: (Box<T>, TypeId)) -> Self
pub fn into_inner(self) -> (Box<T>, TypeId)
Trait Implementations§
Source§impl From<OwnedPtr<CustomType>> for Node
impl From<OwnedPtr<CustomType>> for Node
Source§fn from(ptr: OwnedPtr<CustomType>) -> Node
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
impl From<OwnedPtr<Dictionary>> for Node
Source§fn from(ptr: OwnedPtr<Dictionary>) -> Node
fn from(ptr: OwnedPtr<Dictionary>) -> Node
Wraps the OwnedPtr<Dictionary> in a Node of the corresponding variant Node::Dictionary.
Source§impl From<OwnedPtr<Enumerator>> for Node
impl From<OwnedPtr<Enumerator>> for Node
Source§fn from(ptr: OwnedPtr<Enumerator>) -> Node
fn from(ptr: OwnedPtr<Enumerator>) -> Node
Wraps the OwnedPtr<Enumerator> in a Node of the corresponding variant Node::Enumerator.
Source§impl From<OwnedPtr<ResultType>> for Node
impl From<OwnedPtr<ResultType>> for Node
Source§fn from(ptr: OwnedPtr<ResultType>) -> Node
fn from(ptr: OwnedPtr<ResultType>) -> Node
Wraps the OwnedPtr<ResultType> in a Node of the corresponding variant Node::ResultType.
Source§impl<'a, T: ?Sized, U: ?Sized> PartialEq<&'a T> for OwnedPtr<U>
impl<'a, T: ?Sized, U: ?Sized> PartialEq<&'a T> for OwnedPtr<U>
Source§fn eq(&self, other: &&'a T) -> bool
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
Stringtodyn Displayis 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.
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Attribute>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Attribute>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Attribute>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<CustomType>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<CustomType>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<CustomType>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Dictionary>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Dictionary>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Dictionary>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Enum>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Enum>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Enum>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Enumerator>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Enumerator>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Enumerator>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Field>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Field>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Field>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Interface>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Interface>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Interface>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Module>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Module>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Module>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Operation>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Operation>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Operation>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Parameter>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Parameter>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Parameter>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Primitive>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Primitive>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Primitive>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<ResultType>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<ResultType>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<ResultType>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Sequence>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Sequence>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Sequence>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Struct>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<Struct>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<Struct>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<TypeAlias>
impl<'a> TryFrom<&'a Node> for &'a OwnedPtr<TypeAlias>
Source§fn try_from(node: &'a Node) -> Result<&'a OwnedPtr<TypeAlias>, Self::Error>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Attribute>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<CustomType>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Dictionary>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Enum>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Enumerator>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Field>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Interface>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Module>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Operation>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Parameter>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Primitive>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<ResultType>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Sequence>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<Struct>
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>
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
type Error = LookupError
Source§impl<'a> TryFrom<&'a mut Node> for &'a mut OwnedPtr<TypeAlias>
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>
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.