Skip to main content

BackendTensorCarrier

Struct BackendTensorCarrier 

Source
pub struct BackendTensorCarrier { /* private fields */ }
Expand description

Engine-internal SlotValue wrapping a backend-native tensor behind a type-erased handle. Built by the engine’s wire-decode path (decode_typed_fill backend-mediated branch) from the Backend::materialize_from_wire result; downstream graph ops downcast inner to the backend’s Self::Tensor to read the value.

Lifecycle:

  1. Engine reads an inbound tensor SlotFill, charges its bytes against NodeConfig::ingress_byte_budget, and hands the Vec<u8> to the backend bound to the destination slot via crate::roles::BackendRuntime::materialize_from_wire.
  2. Backend returns a Box<dyn SlotValue> containing this carrier; the engine installs it in the slot table.
  3. On slot overwrite / eviction, the writer reads SlotValue::charged_bytes (returns self.charged_bytes) and releases the budget against the engine counter.

clone_fn + wire_encode_fn carry the per-T::Tensor clone / re-encode shape so the carrier supports the universal SlotValue contract without a Clone / Serialize bound on the type-erased inner. The #[derive(bb::Backend)] derive captures T at the call site and stores these fn pointers in the carrier; intra-Node clones (clone_boxed) and re-encodes (to_wire_bytes) route through them.

Implementations§

Source§

impl BackendTensorCarrier

Source

pub fn from_typed<T>( tensor: T, type_hash: u64, charged_bytes: usize, backend_ref: ComponentRef, ) -> BackendTensorCarrier
where T: Any + Send + Sync + Clone + Serialize + 'static,

Construct a carrier from the backend’s already-typed Self::Tensor. The #[derive(bb::Backend)] materialize bridge is the canonical caller; the constructor is pub so derive expansions in downstream crates can call it, but the engine-side fields (charged_bytes, backend_ref) get stamped via [Self::stamp_engine_fields] immediately after the bridge returns so authoring code never holds a carrier with stale accounting.

Source

pub fn type_hash(&self) -> u64

Borrow the carrier’s wire-type hash. Used by the wire-encode path and by tests that assert a fill’s type discriminator round-trips through the carrier.

Source

pub fn backend_ref(&self) -> ComponentRef

Borrow the producing backend’s ComponentRef. Used by re-encode + introspection.

Source

pub fn downcast_inner<T>(&self) -> Option<&T>
where T: Any + Send + Sync + 'static,

Downcast the type-erased inner tensor to the backend’s concrete Self::Tensor. Engine consumers reach the tensor through this accessor; the inner field stays pub(crate) so external code can’t dodge the downcast + type-hash validation step.

Trait Implementations§

Source§

impl Debug for BackendTensorCarrier

Source§

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

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

impl SlotValue for BackendTensorCarrier

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Downcast surface — recover the concrete type.
Source§

fn into_any_boxed(self: Box<BackendTensorCarrier>) -> Box<dyn Any + Sync + Send>

Repackage Box<dyn SlotValue> as Box<dyn Any> for Box::downcast. Required because the SlotValue and Any vtables are distinct even though SlotValue: Any.
Source§

fn clone_boxed(&self) -> Box<dyn SlotValue>

Polymorphic clone preserving the concrete type.
Source§

fn to_wire_bytes(&self) -> Result<Vec<u8>, SlotValueError>

Wire-boundary encode (bincode + serde). Local forwarding uses clone_boxed instead.
Source§

fn type_hash(&self) -> u64

Stable cross-Node type discriminator. FNV-1a of std::any::type_name::<T>(); receiver decodes only on a matching hash.
Source§

fn charged_bytes(&self) -> usize

Bytes the carrier owes against NodeConfig::ingress_byte_budget. Slot-table eviction calls this to release the charge. Default 0 — only ingress-derived carriers register a non-zero resolver via [register_charged_bytes!].
Source§

fn runtime_type(&self) -> &'static TypeNode

Runtime TypeNode for this value. Returns the leaf registered via [register_type_node!] or TYPE_ANY. Consulted at wire boundaries + TypeSolver seeding; the atomic-dispatch hot path uses compile-time-stamped closures.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedComponent for T
where T: Any + Send + Sync,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more