Trait Writeable

Source
pub trait Writeable {
    // Required method
    fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) -> EncodeResult<()>;
}
Expand description

Trait for an object that can be encoded onto a Writer by reference.

Implement this trait in order to make an object writeable.

Most code won’t need to call this directly, but will instead use it implicitly via the Writer::write() method.

§Example

use tor_bytes::{Writeable, Writer, EncodeResult};
#[derive(Debug, Eq, PartialEq)]
struct Message {
  flags: u32,
  cmd: u8
}

impl Writeable for Message {
    fn write_onto<B:Writer+?Sized>(&self, b: &mut B) -> EncodeResult<()> {
        // We'll say that a "Message" is encoded as flags, then command.
        b.write_u32(self.flags);
        b.write_u8(self.cmd);
        Ok(())
    }
}

let msg = Message { flags: 0x43, cmd: 0x07 };
let mut writer: Vec<u8> = Vec::new();
writer.write(&msg);
assert_eq!(writer, &[0x00, 0x00, 0x00, 0x43, 0x07 ]);

Required Methods§

Source

fn write_onto<B: Writer + ?Sized>(&self, b: &mut B) -> EncodeResult<()>

Encode this object into the writer b.

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.

Implementations on Foreign Types§

Source§

impl Writeable for u8

Source§

impl Writeable for u16

Source§

impl Writeable for u32

Source§

impl Writeable for u64

Source§

impl Writeable for u128

Source§

impl Writeable for Vec<u8>

Source§

impl Writeable for Ipv4Addr

Source§

impl Writeable for Ipv6Addr

Source§

impl Writeable for Ed25519Identity

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for PublicKey

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for PublicKey

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for RsaIdentity

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for SharedSecret

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for Signature

Available on crate feature tor-llcrypto only.
Source§

impl Writeable for [u8]

Source§

impl<N> Writeable for GenericArray<u8, N>
where N: ArrayLength<u8>,

Source§

impl<W: Writeable + ?Sized> Writeable for &W

Source§

impl<const N: usize> Writeable for CtByteArray<N>

Available on crate feature tor-llcrypto only.
Source§

impl<const N: usize> Writeable for [u8; N]

Implementors§

impl Writeable for CircRequestExt

impl Writeable for CircResponseExt

impl Writeable for IntroEstablishedExt

impl Writeable for IntroduceAckExt

impl Writeable for IntroduceExt

impl Writeable for EstablishIntroExt

impl Writeable for OnionKey

impl Writeable for ResolvedVal

impl Writeable for Address

impl Writeable for V1Nonce

impl Writeable for EstablishIntroDetails

impl Writeable for IntroduceHandshakePayload

impl Writeable for IntroduceHeader

impl Writeable for AddressPort

impl<'a, T: ExtGroup> Writeable for ExtListRef<'a, T>

impl<T: ExtGroup> Writeable for ExtList<T>

impl Writeable for CertExt

impl Writeable for SignedWithEd25519Ext

impl Writeable for UnrecognizedExt

impl Writeable for HsBlindId

impl Writeable for HsId

impl Writeable for Effort

impl Writeable for Nonce

impl Writeable for Seed

impl Writeable for SeedHead

impl Writeable for RendCookie

impl Writeable for Subcredential

impl Writeable for LinkSpec

impl Writeable for EncodedLinkSpec

impl<'a> Writeable for Encap<'a>

impl Writeable for NumberedSubver

impl Writeable for SocksAddr