Skip to main content

Encoding

Trait Encoding 

Source
pub trait Encoding: Sealed + 'static {
    const NAME: &'static str;

    // Required method
    fn max_size(sizes: &EncodedSizes) -> Option<u32>;
}
Expand description

A payload encoding. Only the three marker types of this module implement it.

A crate outside ridl-rt names an encoding through this trait:

fn name<E: ridl_rt::encoding::Encoding>() -> &'static str {
    E::NAME
}
assert_eq!(name::<ridl_rt::encoding::ReprC>(), "repr-c");

and cannot add an encoding:

ⓘ
struct Json;

impl ridl_rt::encoding::Encoding for Json {
    const NAME: &'static str = "json";
    fn max_size(sizes: &ridl_rt::contract::EncodedSizes) -> Option<u32> {
        sizes.proto3
    }
}

and cannot implement the sealing trait, because its module is private:

ⓘ
struct Json;

impl ridl_rt::encoding::sealed::Sealed for Json {}

Required Associated Constants§

Source

const NAME: &'static str

The encoding’s name, spelled as its cargo feature is spelled.

Required Methods§

Source

fn max_size(sizes: &EncodedSizes) -> Option<u32>

This encoding’s field of sizes: a payload’s largest encoded size in this encoding, or None when the toolchain cannot size it (EncodedSizes).

A required item, so an encoding added without saying which field it reads does not compile.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl Encoding for FlatBuffers

Source§

const NAME: &'static str = "flatbuffers"

Source§

impl Encoding for Proto3

Source§

const NAME: &'static str = "proto3"

Source§

impl Encoding for ReprC

Source§

const NAME: &'static str = "repr-c"