BitTimingBuilder

Struct BitTimingBuilder 

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

Builder for creating BitTiming programmatically.

This builder allows you to construct bit timing configuration when building DBC files programmatically.

§Examples

use dbc_rs::BitTimingBuilder;

// Empty bit timing (most common)
let bt = BitTimingBuilder::new().build()?;
assert!(bt.is_empty());

// With baudrate only
let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .build()?;
assert_eq!(bt.baudrate(), Some(500000));

// With full timing parameters
let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .btr1(1)
    .btr2(2)
    .build()?;

§Feature Requirements

This builder requires the std feature to be enabled.

Implementations§

Source§

impl BitTimingBuilder

Source

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

Builds the BitTiming from this builder.

§Returns

Returns Ok(BitTiming) with the configured values. Returns an empty BitTiming if no values were set.

§Examples
use dbc_rs::BitTimingBuilder;

let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .btr1(1)
    .btr2(2)
    .build()?;

assert_eq!(bt.baudrate(), Some(500000));
assert_eq!(bt.btr1(), Some(1));
assert_eq!(bt.btr2(), Some(2));
Source§

impl BitTimingBuilder

Source

pub fn new() -> Self

Creates a new BitTimingBuilder with no values set.

§Examples
use dbc_rs::BitTimingBuilder;

let builder = BitTimingBuilder::new();
let bt = builder.build()?;
assert!(bt.is_empty());
Source

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

Sets the baudrate in bits per second.

§Arguments
  • baudrate - The CAN bus baudrate (e.g., 500000 for 500 kbps)
§Examples
use dbc_rs::BitTimingBuilder;

let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .build()?;
assert_eq!(bt.baudrate(), Some(500000));
Source

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

Sets the Bus Timing Register 1 (BTR1) value.

BTR1 is typically only meaningful when baudrate is also set.

§Arguments
  • btr1 - The BTR1 register value
§Examples
use dbc_rs::BitTimingBuilder;

let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .btr1(1)
    .build()?;
assert_eq!(bt.btr1(), Some(1));
Source

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

Sets the Bus Timing Register 2 (BTR2) value.

BTR2 is typically only meaningful when baudrate and BTR1 are also set.

§Arguments
  • btr2 - The BTR2 register value
§Examples
use dbc_rs::BitTimingBuilder;

let bt = BitTimingBuilder::new()
    .baudrate(500000)
    .btr1(1)
    .btr2(2)
    .build()?;
assert_eq!(bt.btr2(), Some(2));

Trait Implementations§

Source§

impl Clone for BitTimingBuilder

Source§

fn clone(&self) -> BitTimingBuilder

Returns a duplicate 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 Debug for BitTimingBuilder

Source§

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

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

impl Default for BitTimingBuilder

Source§

fn default() -> Self

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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, 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.