Skip to main content

DoipMessageBuilder

Struct DoipMessageBuilder 

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

A builder for constructing DoipMessage instances with specified headers and payloads.

This struct provides a fluent interface to configure the protocol version, payload, and automatically populate corresponding header fields based on the payload.

Implementations§

Source§

impl DoipMessageBuilder

Source

pub fn new() -> Self

Creates a new DoipMessageBuilder instance using the default header and payload.

§Example
use doip_definitions::builder::DoipMessageBuilder;
let builder = DoipMessageBuilder::new();
Source

pub fn protocol_version( self, protocol_version: impl Into<ProtocolVersion>, ) -> Self

Sets the protocol version in the header and updates the inverse protocol version accordingly.

§Arguments
  • protocol_version - An object that can be converted into a ProtocolVersion.
§Returns

The updated builder instance for chaining.

§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::ProtocolVersion;
let builder = DoipMessageBuilder::new().protocol_version(ProtocolVersion::Iso13400_2012);
Source

pub fn payload(self, payload: impl Into<DoipPayload>) -> Self

Sets the payload of the message and updates the header’s payload type and length accordingly.

§Arguments
  • payload - An object that can be converted into a DoipPayload.
§Returns

The updated builder instance for chaining.

§Panics

This method panics if the size of the provided payload cannot be determined using core::mem::size_of_val—which may occur if dynamically sized types or trait objects are passed in as payload components.

§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::PayloadType;
use doip_definitions::payload::AliveCheckRequest;
use doip_definitions::payload::DoipPayload;

let builder = DoipMessageBuilder::new().payload(DoipPayload::AliveCheckRequest(AliveCheckRequest {}));
Source

pub fn build(self) -> DoipMessage

Finalizes the builder and returns the constructed DoipMessage.

§Returns

The fully constructed DoipMessage.

§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::PayloadType;
use doip_definitions::payload::AliveCheckRequest;
use doip_definitions::payload::DoipPayload;

let message = DoipMessageBuilder::new()
    .payload(DoipPayload::AliveCheckRequest(AliveCheckRequest {}))
    .build();

Trait Implementations§

Source§

impl Debug for DoipMessageBuilder

Source§

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

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

impl Default for DoipMessageBuilder

Source§

fn default() -> DoipMessageBuilder

Returns the “default value” for a type. Read more

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.