pub trait Ticket: Sized {
const KIND: &'static str;
// Required methods
fn encode_bytes(&self) -> Vec<u8> ⓘ;
fn decode_bytes(bytes: &[u8]) -> Result<Self, ParseError>;
// Provided methods
fn encode_string(&self) -> String { ... }
fn decode_string(s: &str) -> Result<Self, ParseError> { ... }
}Expand description
A ticket is a serializable object combining information required for an operation.
Tickets are convertible to and from a byte representation via encode_bytes /
decode_bytes, and to and from a canonical string form (the lowercase KIND
prefix followed by base32 of the bytes) via encode_string / decode_string.
Implementers only need to provide KIND, encode_bytes, and decode_bytes.
Versioning is left to the implementer. Some kinds of tickets might need versioning, others might not.
The serialization format for converting the ticket from and to bytes is left to the implementer. We recommend using postcard for serialization.
Required Associated Constants§
Required Methods§
Sourcefn encode_bytes(&self) -> Vec<u8> ⓘ
fn encode_bytes(&self) -> Vec<u8> ⓘ
Encode the ticket into its byte representation.
Sourcefn decode_bytes(bytes: &[u8]) -> Result<Self, ParseError>
fn decode_bytes(bytes: &[u8]) -> Result<Self, ParseError>
Decode a ticket from its byte representation.
Provided Methods§
Sourcefn encode_string(&self) -> String
fn encode_string(&self) -> String
Encode the ticket into its canonical string form.
The default implementation produces the lowercase KIND prefix
followed by base32 (no padding) of encode_bytes.
Implementers may override this to use a different string encoding, in which
case decode_string must be overridden to match.
Sourcefn decode_string(s: &str) -> Result<Self, ParseError>
fn decode_string(s: &str) -> Result<Self, ParseError>
Decode a ticket from its canonical string form.
The default implementation expects the lowercase KIND prefix
followed by base32 (no padding) of the bytes accepted by
decode_bytes. Implementers that override
encode_string must override this to match.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".