pub struct Datatype { /* private fields */ }Expand description
A validated SigMF core:datatype value such as cf32_le or ru8.
Construct one by parsing a string with FromStr or from its parts with
Datatype::new. It serializes to and deserializes from its string form,
and deserialization rejects strings that are not core SigMF datatypes.
Implementations§
Source§impl Datatype
impl Datatype
Sourcepub fn new(
domain: SampleDomain,
component: Option<ComponentType>,
endianness: Option<Endianness>,
byte_type: Option<ByteType>,
) -> Result<Self, SigmfError>
pub fn new( domain: SampleDomain, component: Option<ComponentType>, endianness: Option<Endianness>, byte_type: Option<ByteType>, ) -> Result<Self, SigmfError>
Builds a datatype from its domain and component description.
Supply either component and endianness (for multi-byte types) or
only byte_type (for single-byte types).
§Errors
Returns SigmfError::InvalidDataType if any other combination of
component, endianness, and byte_type is given.
§Examples
use sigmf::datatype::{ByteType, ComponentType, Datatype, Endianness, SampleDomain};
let iq = Datatype::new(
SampleDomain::Complex,
Some(ComponentType::I16),
Some(Endianness::BE),
None,
)?;
assert_eq!(iq.as_str(), "ci16_be");
let bytes = Datatype::new(SampleDomain::Real, None, None, Some(ByteType::U8))?;
assert_eq!(bytes.as_str(), "ru8");
assert!(Datatype::new(SampleDomain::Real, Some(ComponentType::F32), None, None).is_err());Sourcepub fn get_domain(&self) -> SampleDomain
pub fn get_domain(&self) -> SampleDomain
Returns whether samples are real or complex.
Sourcepub fn get_dtype(&self) -> Option<ComponentType>
pub fn get_dtype(&self) -> Option<ComponentType>
Returns the multi-byte component type, or None for single-byte
datatypes (see get_byte).
Sourcepub fn get_endian(&self) -> Option<Endianness>
pub fn get_endian(&self) -> Option<Endianness>
Returns the byte order, or None for single-byte datatypes.
Sourcepub fn get_byte(&self) -> Option<ByteType>
pub fn get_byte(&self) -> Option<ByteType>
Returns the single-byte component type, or None for multi-byte
datatypes (see get_dtype).
Sourcepub fn is_complex(&self) -> bool
pub fn is_complex(&self) -> bool
Returns true if the datatype is complex (c prefix).
Sourcepub fn component_bytes(&self) -> usize
pub fn component_bytes(&self) -> usize
Returns the size in bytes of one component (one real value, or one of the I/Q halves of a complex value).
Sourcepub fn bytes_per_channel_sample(&self) -> usize
pub fn bytes_per_channel_sample(&self) -> usize
Returns the size in bytes of one sample on one channel.
This is component_bytes for real datatypes
and twice that for complex datatypes. Multiply by core:num_channels
to get the size of a frame.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Datatype
impl<'de> Deserialize<'de> for Datatype
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Datatype
Source§impl FromStr for Datatype
impl FromStr for Datatype
Source§fn from_str(value: &str) -> Result<Self, Self::Err>
fn from_str(value: &str) -> Result<Self, Self::Err>
Parses a core SigMF datatype string such as cf32_le or ri8.
§Errors
Returns SigmfError::InvalidDataType if the string is empty, has an
unknown domain or component type, is missing or has an invalid
endianness suffix, or adds a suffix to a single-byte type.
Source§type Err = SigmfError
type Err = SigmfError
impl StructuralPartialEq for Datatype
Auto Trait Implementations§
impl Freeze for Datatype
impl RefUnwindSafe for Datatype
impl Send for Datatype
impl Sync for Datatype
impl Unpin for Datatype
impl UnsafeUnpin for Datatype
impl UnwindSafe for Datatype
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more