iroh_base::ticket

Trait Ticket

Source
pub trait Ticket: Sized {
    const KIND: &'static str;

    // Required methods
    fn to_bytes(&self) -> Vec<u8>;
    fn from_bytes(bytes: &[u8]) -> Result<Self, Error>;

    // Provided methods
    fn serialize(&self) -> String { ... }
    fn deserialize(str: &str) -> Result<Self, Error> { ... }
}
Available on crate feature base32 only.
Expand description

A ticket is a serializable object combining information required for an operation.

Typically tickets contain all information required for an operation, e.g. an iroh blob ticket would contain the hash of the data as well as information about how to reach the provider.

Tickets support serialization to a string using base32 encoding. The kind of ticket will be prepended to the string to make it somewhat self describing.

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§

Source

const KIND: &'static str

String prefix describing the kind of iroh ticket.

This should be lower case ascii characters.

Required Methods§

Source

fn to_bytes(&self) -> Vec<u8>

Serialize to bytes used in the base32 string representation.

Source

fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

Deserialize from the base32 string representation bytes.

Provided Methods§

Source

fn serialize(&self) -> String

Serialize to string.

Source

fn deserialize(str: &str) -> Result<Self, Error>

Deserialize from a string.

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 Ticket for BlobTicket

Available on crate feature key only.
Source§

const KIND: &'static str = "blob"

Source§

impl Ticket for NodeTicket

Available on crate feature key only.
Source§

const KIND: &'static str = "node"