Trait libp2p::request_response::codec::ProtocolName[][src]

pub trait ProtocolName {
    pub fn protocol_name(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
; }

Types serving as protocol names.

Context

In situations where we provide a list of protocols that we support, the elements of that list are required to implement the ProtocolName trait.

Libp2p will call ProtocolName::protocol_name on each element of that list, and transmit the returned value on the network. If the remote accepts a given protocol, the element serves as the return value of the function that performed the negotiation.

Example

use libp2p_core::ProtocolName;

enum MyProtocolName {
    Version1,
    Version2,
    Version3,
}

impl ProtocolName for MyProtocolName {
    fn protocol_name(&self) -> &[u8] {
        match *self {
            MyProtocolName::Version1 => b"/myproto/1.0",
            MyProtocolName::Version2 => b"/myproto/2.0",
            MyProtocolName::Version3 => b"/myproto/3.0",
        }
    }
}

Required methods

pub fn protocol_name(&self) -> &[u8]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
[src]

The protocol name as bytes. Transmitted on the network.

Note: Valid protocol names must start with / and not exceed 140 bytes in length.

Loading content...

Implementors

impl<A, B> ProtocolName for EitherName<A, B> where
    A: ProtocolName,
    B: ProtocolName
[src]

impl<H> ProtocolName for IndexedProtoName<H> where
    H: ProtocolName
[src]

impl<T> ProtocolName for T where
    T: AsRef<[u8]>, 
[src]

Loading content...