Skip to main content

ConverterImpl

Struct ConverterImpl 

Source
pub struct ConverterImpl<M = ()> {
    pub destination: Type,
    pub function: ItemFn,
    pub pre_stages: Vec<Stage<M>>,
    pub niches: Niches,
    pub metadata: M,
    pub subs: Vec<TypeKey>,
}
Expand description

Result of resolving one converter — the wire (destination) type the rest of the registry sees, plus the complete generated function.

Invariant: function.sig.ident MUST be a deterministic function of the (rust_type, destination) pair so that callers of this converter — both other generated converters from the same adapter and any hand-written code that knows the convention — can compute or look up the name.

Fields§

§destination: Type

Wire/destination type. Other converters that ask “what’s the wire form of this rust type?” read this. The actual function may return a wrapped form (e.g. an adapter’s own Result-like envelope) — that is the adapter’s internal calling convention; destination is the value the wire carries on success.

§function: ItemFn

Complete function definition for the wire-facing stage. The adapter owns the parameter list, return type, unsafe/pub modifiers, lifetime parameters, and any attribute annotations. For input direction this is the FIRST stage in execution order (it takes the wire); for output direction this is the LAST stage (it produces the wire).

§pre_stages: Vec<Stage<M>>

Rust-side stages that compose with Self::function to form the full conversion chain. Default empty — a 1-stage converter is just function.

Order is rust-side-first → function-side-last. Concretely:

  • Input (wire → rust): chain runs wire → function → pre_stages[0] → pre_stages[1] → … → pre_stages[N-1] → rust.
  • Output (rust → wire): chain runs rust → pre_stages[N-1] → … → pre_stages[1] → pre_stages[0] → function → wire.

Each stage is fallible; how its Err arm is surfaced is adapter specific and carried in Stage::metadata.

§niches: Niches

Bit-patterns the wire type can represent but this converter never produces (output) and rejects (input). Wrapper handlers like Option<_> consume one slot for their own discriminant and re-export the rest — see Niches for the cascade model. Default is empty (no niche optimisation).

§metadata: M

Adapter-specific extras carried alongside the converter. Filled by the same handler that produces destination / function / niches, copied through into TypeEntry::metadata by the resolver, and read by the adapter’s language-side emitters. Set this where you build the converter, not in a side channel.

§subs: Vec<TypeKey>

Inner types this converter composed from — the types whose input_entry/output_entry the adapter looked up to build a wrapper (Option<X>[X], Result<T,E>[T, E], &T[&T]). Empty for a terminal converter (scalar, opaque handle, string) and for a callback’s own converter (callback args are cross-direction — their required-ness flows through the registry’s type-graph edges, not here). The resolver copies these into TypeEntry::subs, which propagate_required walks to mark reachable types required.

Identities, not spellings. They are looked up and walked, never emitted — TypeEntry::subs was already Vec<TypeKey> and the resolver keyed these on arrival, so the spelling existed only to be converted. An adapter that composed the inner type keys it (TypeKey::from_type); one that read it off the model asks the reading (TypeRef::key), and names no escape to do it.

Trait Implementations§

Source§

impl<M: Clone> Clone for ConverterImpl<M>

Source§

fn clone(&self) -> ConverterImpl<M>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<M = ()> !Send for ConverterImpl<M>

§

impl<M = ()> !Sync for ConverterImpl<M>

§

impl<M> Freeze for ConverterImpl<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for ConverterImpl<M>
where M: RefUnwindSafe,

§

impl<M> Unpin for ConverterImpl<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for ConverterImpl<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for ConverterImpl<M>
where M: UnwindSafe,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.