#[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
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
impl DetectMode
Sourcepub const ALL: &'static [Self]
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.
Sourcepub const fn to_sys(self) -> BelaHwDetectMode
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
impl Clone for DetectMode
Source§fn clone(&self) -> DetectMode
fn clone(&self) -> DetectMode
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more