rama_haproxy::protocol::v2

Struct Header

Source
pub struct Header<'a> {
    pub header: Cow<'a, [u8]>,
    pub version: Version,
    pub command: Command,
    pub protocol: Protocol,
    pub addresses: Addresses,
}
Expand description

A proxy protocol version 2 header.

§Examples

use rama_haproxy::protocol::v2::{Addresses, AddressFamily, Command, Header, IPv4, ParseError, Protocol, PROTOCOL_PREFIX, Type, TypeLengthValue, Version};
let mut header = Vec::from(PROTOCOL_PREFIX);
header.extend([
   0x21, 0x12, 0, 16, 127, 0, 0, 1, 192, 168, 1, 1, 0, 80, 1, 187, 4, 0, 1, 42
]);

let addresses: Addresses = IPv4::new([127, 0, 0, 1], [192, 168, 1, 1], 80, 443).into();
let expected = Header {
   header: header.as_slice().into(),
   version: Version::Two,
   command: Command::Proxy,
   protocol: Protocol::Datagram,
   addresses
};
let actual = Header::try_from(header.as_slice()).unwrap();

assert_eq!(actual, expected);
assert_eq!(actual.tlvs().collect::<Vec<Result<TypeLengthValue<'_>, ParseError>>>(), vec![Ok(TypeLengthValue::new(Type::NoOp, &[42]))]);

Fields§

§header: Cow<'a, [u8]>

The underlying byte slice this Header is built on.

§version: Version

The version of the PROXY protocol.

§command: Command

The command of the PROXY protocol.

§protocol: Protocol

The protocol of the PROXY protocol.

§addresses: Addresses

The source and destination addresses of the PROXY protocol.

Implementations§

Source§

impl Header<'_>

Source

pub fn to_owned(&self) -> Header<'static>

Creates an owned clone of this Header.

Source

pub fn length(&self) -> usize

The length of this Header’s payload in bytes.

Source

pub fn len(&self) -> usize

The total length of this Header in bytes.

Source

pub fn is_empty(&self) -> bool

Tests whether this Header’s underlying byte slice is empty.

Source

pub fn address_family(&self) -> AddressFamily

The AddressFamily of this Header.

Source

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

The bytes of the address portion of the payload.

Source

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

The bytes of the TypeLengthValue portion of the payload.

Source

pub fn tlvs(&self) -> TypeLengthValues<'_>

An Iterator of TypeLengthValues.

Source

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

The underlying byte slice this Header is built on.

Trait Implementations§

Source§

impl<'a> Clone for Header<'a>

Source§

fn clone(&self) -> Header<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Header<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Header<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Hash for Header<'a>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for Header<'a>

Source§

fn eq(&self, other: &Header<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a [u8]> for Header<'a>

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(input: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> Eq for Header<'a>

Source§

impl<'a> StructuralPartialEq for Header<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Header<'a>

§

impl<'a> RefUnwindSafe for Header<'a>

§

impl<'a> Send for Header<'a>

§

impl<'a> Sync for Header<'a>

§

impl<'a> Unpin for Header<'a>

§

impl<'a> UnwindSafe for Header<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more