Skip to main content

libbladerf_rs/
channel.rs

1use crate::{Error, Result};
2#[derive(PartialEq, Debug, Clone, Copy)]
3#[repr(u8)]
4pub enum Channel {
5    Rx = 0,
6    Tx = 1,
7}
8impl Channel {
9    pub fn is_tx(&self) -> bool {
10        *self == Channel::Tx
11    }
12    pub fn is_rx(&self) -> bool {
13        *self == Channel::Rx
14    }
15}
16impl TryFrom<u8> for Channel {
17    type Error = Error;
18    fn try_from(value: u8) -> Result<Self> {
19        match value {
20            0 => Ok(Channel::Rx),
21            1 => Ok(Channel::Tx),
22            _ => {
23                log::error!("unsupported channel!");
24                Err(Error::Invalid)
25            }
26        }
27    }
28}