Skip to main content

SamplePoint

Struct SamplePoint 

Source
pub struct SamplePoint(/* private fields */);
Expand description

Bit-timing sample point as a fraction of the bit time.

Stored internally as per-mille (e.g., 875 for 87.5%). The CAN specification recommends sample points in the 70%–87.5% range; this type enforces [500, 950] per-mille (50%–95%) so out-of-range values are rejected before they reach a backend’s timing solver.

Construct via SamplePoint::from_per_mille (const fn, so out-of-range literals fail at compile time when wrapped in a const context), or via the preset constants:

use can_hal::SamplePoint;

// Compile-time literal (asserted at compile time when used in a const context):
const SP_87_5: SamplePoint = SamplePoint::from_per_mille(875);
assert_eq!(SP_87_5.per_mille(), 875);

// Or use a preset:
assert_eq!(SamplePoint::NOMINAL_DEFAULT.per_mille(), 700);
assert_eq!(SamplePoint::DATA_DEFAULT.per_mille(), 800);

Out-of-range per-mille values panic - at compile time in a const context, or at runtime otherwise:

const TOO_HIGH: SamplePoint = SamplePoint::from_per_mille(2000);
// Runtime construction with an out-of-range value panics.
SamplePoint::from_per_mille(2000);

Implementations§

Source§

impl SamplePoint

Source

pub const NOMINAL_DEFAULT: Self

Default nominal-phase sample point: 70%. Matches the cross-adapter interop convention used by the PCAN and Kvaser backends in this workspace.

Source

pub const DATA_DEFAULT: Self

Default data-phase sample point: 80%. Matches the cross-adapter interop convention used by the PCAN and Kvaser backends in this workspace.

Source

pub const PCT_75: Self

75% sample point.

Source

pub const PCT_87_5: Self

87.5% sample point - a common industrial recommendation for classic CAN at modest bus lengths.

Source

pub const fn from_per_mille(per_mille: u16) -> Self

Construct from per-mille (e.g., 875 for 87.5%, 700 for 70%).

Panics if per_mille is outside [500, 950]. In a const context (i.e., when initializing a const binding or inside const { ... }), this panic occurs at compile time.

Source

pub const fn per_mille(self) -> u16

Get the per-mille value (e.g., 875 for 87.5%).

Source

pub fn as_fraction(self) -> f32

Convert to a fraction (e.g., 0.875 for 87.5%). Not const because f32 division isn’t const-stable on this crate’s MSRV.

Trait Implementations§

Source§

impl Clone for SamplePoint

Source§

fn clone(&self) -> SamplePoint

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for SamplePoint

Source§

impl Debug for SamplePoint

Source§

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

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

impl Eq for SamplePoint

Source§

impl PartialEq for SamplePoint

Source§

fn eq(&self, other: &SamplePoint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for SamplePoint

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.