ValueDescriptionsBuilder

Struct ValueDescriptionsBuilder 

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

Builder for creating ValueDescriptions programmatically.

This builder allows you to construct value descriptions when building DBC files programmatically. It validates that entries are within limits.

§Examples

use dbc_rs::ValueDescriptionsBuilder;

let value_descriptions = ValueDescriptionsBuilder::new()
    .add_entry(0, "Park")
    .add_entry(1, "Reverse")
    .add_entry(2, "Neutral")
    .add_entry(3, "Drive")
    .build()?;

assert_eq!(value_descriptions.get(0), Some("Park"));
assert_eq!(value_descriptions.get(1), Some("Reverse"));

§Validation

The builder validates:

  • Maximum of 64 value descriptions (MAX_VALUE_DESCRIPTIONS)

§Feature Requirements

This builder requires the std feature to be enabled.

Implementations§

Source§

impl ValueDescriptionsBuilder

Source

pub fn new() -> Self

Creates a new ValueDescriptionsBuilder with an empty entry list.

§Examples
use dbc_rs::ValueDescriptionsBuilder;

let builder = ValueDescriptionsBuilder::new();
let value_descriptions = builder.build()?;
assert!(value_descriptions.is_empty());
Source

pub fn add_entry(self, value: u64, description: impl AsRef<str>) -> Self

Adds a value-description pair to the builder.

§Arguments
  • value - The numeric value (u64)
  • description - The human-readable description
§Examples
use dbc_rs::ValueDescriptionsBuilder;

let builder = ValueDescriptionsBuilder::new()
    .add_entry(0, "Off")
    .add_entry(1, "On");
Source

pub fn build(self) -> Result<ValueDescriptions>

Builds the ValueDescriptions from the builder.

§Errors

Returns an error if the number of entries exceeds the maximum allowed.

§Examples
use dbc_rs::ValueDescriptionsBuilder;

let value_descriptions = ValueDescriptionsBuilder::new()
    .add_entry(0, "Park")
    .add_entry(1, "Drive")
    .build()?;

Trait Implementations§

Source§

impl Debug for ValueDescriptionsBuilder

Source§

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

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

impl Default for ValueDescriptionsBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.