NetMessageBuilder

Struct NetMessageBuilder 

Source
pub struct NetMessageBuilder { /* private fields */ }
Expand description

Fluent builder for constructing network messages

§Examples

use lnmp_core::{LnmpRecord, LnmpField, LnmpValue};
use lnmp_envelope::EnvelopeBuilder;
use lnmp_net::{MessageKind, NetMessageBuilder};

let mut record = LnmpRecord::new();
record.add_field(LnmpField { fid: 12, value: LnmpValue::Int(42) });

let envelope = EnvelopeBuilder::new(record)
    .timestamp(1700000000000)
    .source("service-a")
    .build();

let msg = NetMessageBuilder::new(envelope, MessageKind::Alert)
    .priority(255)
    .ttl_ms(1000)
    .class("safety")
    .build();

assert_eq!(msg.priority, 255);
assert_eq!(msg.class, Some("safety".to_string()));

Implementations§

Source§

impl NetMessageBuilder

Source

pub fn new(envelope: LnmpEnvelope, kind: MessageKind) -> Self

Creates a new builder with defaults from MessageKind

Source

pub fn priority(self, priority: u8) -> Self

Sets the priority (0-255)

Source

pub fn ttl_ms(self, ttl_ms: u32) -> Self

Sets the TTL in milliseconds

Source

pub fn class(self, class: impl Into<String>) -> Self

Sets the domain class

Source

pub fn build(self) -> NetMessage

Builds the NetMessage

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.