Skip to main content

DetectMode

Enum DetectMode 

Source
#[non_exhaustive]
pub enum DetectMode { Scan, Cache, CacheOnly, User, UserOnly, }
Expand description

How Board::detect should go about finding out.

The modes are not interchangeable and none of them is a safe default for every caller: they differ in which file they trust, whether they fall back to scanning, and whether an answer of Board::NoHardware means “nothing there” or “nobody wrote it down”. Two files are involved — /run/bela/belaconfig, which the Bela daemon writes, and ~/.bela/belaconfig, where a user overrides it.

Not exhaustive: the modes are libbela’s, and an image that adds one adds it here rather than in this crate’s idea of the list.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Scan

Scan the peripherals and buses, and cache the result in /run/bela/belaconfig.

The only mode that writes anything, and the only one whose cost is a bus transaction rather than a file read. It needs permission to write the cache, which a program not running as root may not have.

§

Cache

Read /run/bela/belaconfig, and Scan if it is not there.

What a program wants when it just needs the answer: on a running board the daemon has already written the file, so this is a file read.

§

CacheOnly

Read /run/bela/belaconfig, and answer Board::NoHardware if it is not there.

§

User

Read ~/.bela/belaconfig, and fall back to Cache if it is not there.

§

UserOnly

Read ~/.bela/belaconfig, and answer Board::NoHardware if it is not there.

The mode that asks what the user asked for, and nothing else. On a board with no such file — the measured one had none — it answers Board::NoHardware however plainly the hardware is there.

Implementations§

Source§

impl DetectMode

Source

pub const ALL: &'static [Self]

Every mode, in the order the C enum declares them.

For a program that reports what each one says rather than choosing between them — which is how the difference between them was measured. The order is the declaration’s, not an order to ask them in: Scan writes the file the three cache and user modes read, so a program calling all of them leaves it until last.

A slice rather than an array, because the length is the C enum’s: an image that adds a mode makes this longer, and a caller that had written down how many there were would be the only thing that broke.

Source

pub const fn to_sys(self) -> BelaHwDetectMode

The BelaHwDetectMode this mode is.

Also available as BelaHwDetectMode::from(mode) and mode.into(); this is the one that works in a const. There is no way back: a BelaHwDetectMode this crate does not name would have to be refused rather than carried, which makes the reverse a TryFrom — and nothing hands a mode to a caller, so there is nothing for it to convert.

Trait Implementations§

Source§

impl Clone for DetectMode

Source§

fn clone(&self) -> DetectMode

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 DetectMode

Source§

impl Debug for DetectMode

Source§

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

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

impl Display for DetectMode

Source§

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

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

impl Eq for DetectMode

Source§

impl From<DetectMode> for BelaHwDetectMode

Source§

fn from(mode: DetectMode) -> Self

Converts to this type from the input type.
Source§

impl Hash for DetectMode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DetectMode

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DetectMode

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.