ForeignType

Trait ForeignType 

Source
pub trait ForeignType {
    // Required methods
    fn assignable_from(&self, type_: &Type) -> bool;
    fn assignable_to(&self, type_: &Type) -> bool;
    fn type_ref(&self) -> TokenStream;
    fn decoding_gen(
        &self,
        source: TokenStream,
        output_ref: TokenStream,
        arguments: Vec<TokenStream>,
        is_async: bool,
    ) -> TokenStream;
    fn encoding_gen(
        &self,
        target: TokenStream,
        field_ref: TokenStream,
        arguments: Vec<TokenStream>,
        is_async: bool,
    ) -> TokenStream;
    fn arguments(&self) -> Vec<TypeArgument>;
    fn can_receive_auto(&self) -> Option<ScalarType>;

    // Provided methods
    fn assignable_from_partial(&self, type_: &PartialType) -> bool { ... }
    fn assignable_to_partial(&self, type_: &PartialType) -> bool { ... }
}
Expand description

An encodable and decodable foreign type object Generally these are used to represent complexly encoded types, where there isn’t a notion of smaller internal types

Good examples: Custom encoded integers (i.e. varints) UTF8 strings

Bad examples: GZIP encoded data Encrypted data

Required Methods§

Source

fn assignable_from(&self, type_: &Type) -> bool

Is this type assignable from this other type? i.e. let X: ThisType = OtherType;

Source

fn assignable_to(&self, type_: &Type) -> bool

Is this type assignable to this other type? i.e. let X: OtherType = ThisType; Generally identical to ForeignType::assignable_from

Source

fn type_ref(&self) -> TokenStream

Emits this type as a Rust type

Source

fn decoding_gen( &self, source: TokenStream, output_ref: TokenStream, arguments: Vec<TokenStream>, is_async: bool, ) -> TokenStream

output code should be a term expression that:

  1. the expression should read its input from an implicit identifier reader as a &mut R where R: Read
  2. can read an arbitrary number of bytes from reader
  3. returns a value of the foreign type
Source

fn encoding_gen( &self, target: TokenStream, field_ref: TokenStream, arguments: Vec<TokenStream>, is_async: bool, ) -> TokenStream

output code should be a single statement that:

  1. takes an expression field_ref as a reference to a value of the foreign type
  2. the statement should write its output to an implicit identifier writer as a &mut W where W: Write
Source

fn arguments(&self) -> Vec<TypeArgument>

All arguments that can be passed to this type to describe characteristics (i.e. string length) All optional arguments must come at the end of the list of arguments.

Source

fn can_receive_auto(&self) -> Option<ScalarType>

If Some, this type can receive auto defined lengths during encoding

Provided Methods§

Source

fn assignable_from_partial(&self, type_: &PartialType) -> bool

An internal modified form of ForeignType::assignable_from to provide some flexibility in type checking.

Source

fn assignable_to_partial(&self, type_: &PartialType) -> bool

An internal modified form of ForeignType::assignable_to to provide some flexibility in type checking.

Implementors§