Skip to main content

ObjectRefCore

Trait ObjectRefCore 

Source
pub unsafe trait ObjectRefCore: Sized + Clone {
    type ContainerType: ObjectCore;

    // Required methods
    fn data(this: &Self) -> &ObjectArc<Self::ContainerType>;
    fn into_data(this: Self) -> ObjectArc<Self::ContainerType>;
    unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self;

    // Provided methods
    fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool { ... }
    fn as_node<N: ObjectCore>(&self) -> Option<&N> { ... }
}
Expand description

Traits to specify core operations of ObjectRef

used by the ffi Any system and not user facing

We mark as unsafe since it moves out the internal of the ObjectRef

§Safety

data, into_data, and from_data must preserve the same object allocation and form an ownership-preserving round trip. That allocation must start with a valid TVMFFIObject header whose registered object-range runtime type index correctly describes its layout and inheritance.

When Self also implements AnyCompatible, copy_to_any_view must produce a non-owning view, while move_to_any must transfer ownership of the same object pointer and dynamic type index. move_from_any_after_check must be able to reclaim that owned representation exactly once, and a true check_any_strict result must guarantee that both after-check constructors are valid for it.

Required Associated Types§

Required Methods§

Source

fn data(this: &Self) -> &ObjectArc<Self::ContainerType>

Source

fn into_data(this: Self) -> ObjectArc<Self::ContainerType>

Source

unsafe fn from_data(data: ObjectArc<Self::ContainerType>) -> Self

Construct a reference view from an owning container handle.

§Safety

In addition to containing a valid ContainerType allocation, data must satisfy every semantic invariant imposed by Self. This matters for zero-state views that share a container type but accept only a subset of its values, such as a typed expression view.

Provided Methods§

Source

fn same_as<Other: ObjectRefCore>(&self, other: &Other) -> bool

Return whether two object references point to the same allocation.

Source

fn as_node<N: ObjectCore>(&self) -> Option<&N>

Borrow the underlying object as node type N when its runtime type matches.

Unlike ObjectRefCast::try_cast, this method neither consumes the reference nor changes the object’s reference count. The returned node cannot outlive self.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§