Trait ResolvedTypeVisitor

Source
pub trait ResolvedTypeVisitor<'resolver>: Sized {
    type TypeId: TypeId + 'static;
    type Value;

    // Required method
    fn visit_unhandled(self, kind: UnhandledKind) -> Self::Value;

    // Provided methods
    fn visit_not_found(self) -> Self::Value { ... }
    fn visit_composite<Path, Fields>(
        self,
        _path: Path,
        _fields: Fields,
    ) -> Self::Value
       where Path: PathIter<'resolver>,
             Fields: FieldIter<'resolver, Self::TypeId> { ... }
    fn visit_variant<Path, Fields, Var>(
        self,
        _path: Path,
        _variants: Var,
    ) -> Self::Value
       where Path: PathIter<'resolver>,
             Fields: FieldIter<'resolver, Self::TypeId>,
             Var: VariantIter<'resolver, Fields> { ... }
    fn visit_sequence<Path>(
        self,
        _path: Path,
        _type_id: Self::TypeId,
    ) -> Self::Value
       where Path: PathIter<'resolver> { ... }
    fn visit_array(self, _type_id: Self::TypeId, _len: usize) -> Self::Value { ... }
    fn visit_tuple<TypeIds>(self, _type_ids: TypeIds) -> Self::Value
       where TypeIds: ExactSizeIterator<Item = Self::TypeId> { ... }
    fn visit_primitive(self, _primitive: Primitive) -> Self::Value { ... }
    fn visit_compact(self, _type_id: Self::TypeId) -> Self::Value { ... }
    fn visit_bit_sequence(
        self,
        _store_format: BitsStoreFormat,
        _order_format: BitsOrderFormat,
    ) -> Self::Value { ... }
}
Expand description

A glorified set of callbacks, exactly one of which will fire depending on the outcome of calling TypeResolver::resolve_type(). These don’t typically need to be implemented by the user, and instead are implemented internally in eg scale-decode to drive the decoding of types.

The lifetime held by this trait is the lifetime of the type resolver. Various inputs to the callbacks are thus bound by this lifetime, and it’s possible to return values which contain this lifetime.

Required Associated Types§

Source

type TypeId: TypeId + 'static

The type ID type that the TypeResolver is using.

Source

type Value

Some value that can be returned from the called method.

Required Methods§

Source

fn visit_unhandled(self, kind: UnhandledKind) -> Self::Value

Called when the actual method to be called was not implemented.

Provided Methods§

Source

fn visit_not_found(self) -> Self::Value

Called when the type ID passed to TypeResolver::resolve_type() was not found.

Source

fn visit_composite<Path, Fields>( self, _path: Path, _fields: Fields, ) -> Self::Value
where Path: PathIter<'resolver>, Fields: FieldIter<'resolver, Self::TypeId>,

Called when the type ID corresponds to a composite type. This is provided an iterator over each of the fields and their type IDs that the composite type contains.

Source

fn visit_variant<Path, Fields, Var>( self, _path: Path, _variants: Var, ) -> Self::Value
where Path: PathIter<'resolver>, Fields: FieldIter<'resolver, Self::TypeId>, Var: VariantIter<'resolver, Fields>,

Called when the type ID corresponds to a variant type. This is provided the list of variants (and for each variant, the fields within it) that the type could be encoded as.

Source

fn visit_sequence<Path>( self, _path: Path, _type_id: Self::TypeId, ) -> Self::Value
where Path: PathIter<'resolver>,

Called when the type ID corresponds to a sequence of values of some type ID (which is provided as an argument here). The length of the sequence is compact encoded first.

Source

fn visit_array(self, _type_id: Self::TypeId, _len: usize) -> Self::Value

Called when the type ID corresponds to an array of values of some type ID (which is provided as an argument here). The length of the array is known at compile time and is also provided.

Source

fn visit_tuple<TypeIds>(self, _type_ids: TypeIds) -> Self::Value
where TypeIds: ExactSizeIterator<Item = Self::TypeId>,

Called when the type ID corresponds to a tuple of values whose type IDs are provided here.

Source

fn visit_primitive(self, _primitive: Primitive) -> Self::Value

Called when the type ID corresponds to some primitive type. The exact primitive type is provided in th form of an enum.

Source

fn visit_compact(self, _type_id: Self::TypeId) -> Self::Value

Called when the type ID corresponds to a compact encoded type. The type ID of the inner type is provided.

Source

fn visit_bit_sequence( self, _store_format: BitsStoreFormat, _order_format: BitsOrderFormat, ) -> Self::Value

Called when the type ID corresponds to a bit sequence, whose store and order types are given.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'resolver, Context, TypeId, Output, UnhandledFn, NotFoundFn, CompositeFn, VariantFn, SequenceFn, ArrayFn, TupleFn, PrimitiveFn, CompactFn, BitSequenceFn> ResolvedTypeVisitor<'resolver> for ConcreteResolvedTypeVisitor<'resolver, Context, TypeId, Output, UnhandledFn, NotFoundFn, CompositeFn, VariantFn, SequenceFn, ArrayFn, TupleFn, PrimitiveFn, CompactFn, BitSequenceFn>
where TypeId: Clone + Default + Debug + 'static, UnhandledFn: FnOnce(Context, UnhandledKind) -> Output, NotFoundFn: FnOnce(Context) -> Output, CompositeFn: FnOnce(Context, &mut dyn PathIter<'resolver>, &mut dyn FieldIter<'resolver, TypeId>) -> Output, VariantFn: FnOnce(Context, &mut dyn PathIter<'resolver>, &mut dyn VariantIter<'resolver, ConcreteFieldIter<'resolver, TypeId>>) -> Output, SequenceFn: FnOnce(Context, &mut dyn PathIter<'resolver>, TypeId) -> Output, ArrayFn: FnOnce(Context, TypeId, usize) -> Output, TupleFn: FnOnce(Context, &mut dyn ExactSizeIterator<Item = TypeId>) -> Output, PrimitiveFn: FnOnce(Context, Primitive) -> Output, CompactFn: FnOnce(Context, TypeId) -> Output, BitSequenceFn: FnOnce(Context, BitsStoreFormat, BitsOrderFormat) -> Output,

Source§

type TypeId = TypeId

Source§

type Value = Output