Trait saltpig::extensions::Extension[][src]

pub trait Extension: Into<Value> + TryFrom<Value> {
    const TAG: u64;
}

The extension trait.

This trait marks types which are extensions. Each extension type T knows four things:

  • What CBOR tag belongs to it
  • How to convert a T into a Value
  • How to tell whether a given Value represents a valid T
  • How to convert a Value that represents a T into an actual T

These are enforced by the Into<Value> and TryFrom<Value> bounds, and the TAG associated const.

Normally, a Value represents a T if it is a Tagged and the tag matches T::TAG, with its classification as representing a valid T conditional on the inner value conforming to some specific structure (for example, to be a valid Uuid, a value with tag 37 must be a byte string with length 16).

Extension types are expected to meet saltpig's ergonomic standards. For example, an extension type representing a bignum should implement standard conversions from and to the relevant bignum type (as well as the required conversions from and to Value).

Examples

Each of the submodules is an example. extensions::uuid is a nice and simple one.

Associated Constants

The tag value belonging to this extension type.

Implementors