pub struct CustomAddr { /* private fields */ }key only.Expand description
A custom transport address consisting of a transport id and opaque address data.
This is a generic address type that allows external crates to implement custom transports for iroh.
Transport ids are freely chosen u64 numbers. A registry for well-known transport ids is maintained at https://github.com/n0-computer/iroh/blob/main/TRANSPORTS.md. The opaque address data is not validated or size-limited in any way.
§String encoding
Used by Display and FromStr implementations.
Format: <id>_<data> where <id> is the transport id as lowercase hex (no 0x
prefix, no leading zeros) and <data> is the address bytes as lowercase hex,
separated by _.
§Binary encoding
Used by Self::to_vec and Self::from_bytes.
Format: 8-byte little-endian u64 transport id, followed by raw address data bytes.
The minimum valid length is 8 bytes (id only with empty data).
Implementations§
Source§impl CustomAddr
impl CustomAddr
Sourcepub fn from_parts(id: u64, data: &[u8]) -> Self
pub fn from_parts(id: u64, data: &[u8]) -> Self
Creates a new CustomAddr from a transport id and raw address data.
Sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Returns the transport id.
You can freely choose this. There is a table of reserved custom transport ids in https://github.com/n0-computer/iroh/blob/main/TRANSPORTS.md, where you could submit your transport for registration to get a reserved id.
But this is only relevant if you care for interop.
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
Returns the opaque address data for this transport.
Below a certain size (currently 30 bytes) this is stored inline, otherwise on the heap.
Note that there are no guarantees about the size of this data. When parsing custom addresses you must be prepared to handle unexpected sizes here.
Sourcepub fn to_vec(&self) -> Vec<u8> ⓘ
pub fn to_vec(&self) -> Vec<u8> ⓘ
Serializes to the binary encoding.
See CustomAddr docs for details on the encoding.
Sourcepub fn from_bytes(data: &[u8]) -> Result<Self, &'static str>
pub fn from_bytes(data: &[u8]) -> Result<Self, &'static str>
Parses from the binary encoding.
See CustomAddr docs for details on the encoding.
Trait Implementations§
Source§impl Clone for CustomAddr
impl Clone for CustomAddr
Source§fn clone(&self) -> CustomAddr
fn clone(&self) -> CustomAddr
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CustomAddr
impl Debug for CustomAddr
Source§impl<'de> Deserialize<'de> for CustomAddr
impl<'de> Deserialize<'de> for CustomAddr
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for CustomAddr
impl Display for CustomAddr
impl Eq for CustomAddr
Source§impl FromStr for CustomAddr
impl FromStr for CustomAddr
Source§impl Hash for CustomAddr
impl Hash for CustomAddr
Source§impl Ord for CustomAddr
impl Ord for CustomAddr
Source§fn cmp(&self, other: &CustomAddr) -> Ordering
fn cmp(&self, other: &CustomAddr) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for CustomAddr
impl PartialEq for CustomAddr
Source§fn eq(&self, other: &CustomAddr) -> bool
fn eq(&self, other: &CustomAddr) -> bool
self and other values to be equal, and is used by ==.