Struct flipdot_core::Data [−][src]
Owned or borrowed data to be placed in a Frame.
Since the data length in the Frame will be represented as a single byte,
that length cannot exceed 255 (0xFF). Data is responsible for maintaining
this invariant.
Examples
use flipdot_core::{Address, Data, Frame, MsgType}; let data = Data::try_new(vec![1, 2, 3])?; // Ok since length under 255 let frame = Frame::new(Address(2), MsgType(1), data);
Implementations
impl<'a> Data<'a>[src]
pub fn try_new<T: Into<Cow<'a, [u8]>>>(data: T) -> Result<Self, FrameError>[src]
Creates a new Data containing owned or borrowed data.
Since the data length in the Frame will be represented as a single byte,
that length cannot exceed 255 (0xFF).
Errors
Returns FrameError::DataTooLong if the data length is greater than 255 (0xFF).
Examples
use flipdot_core::Data; let data = Data::try_new(vec![1, 2, 3])?; assert_eq!(vec![1, 2, 3], data.get().as_ref());
Borrowed data can also be used:
let bytes = vec![1, 2, 3]; let data = Data::try_new(&bytes)?; assert_eq!(vec![1, 2, 3], data.get().as_ref());
This will fail since the passed-in vector is too large:
let result = Data::try_new(vec![0; 1000]); assert!(result.is_err());
pub fn get(&self) -> &Cow<'a, [u8]>[src]
Trait Implementations
impl<'a> Clone for Data<'a>[src]
impl<'a> Debug for Data<'a>[src]
impl<'a> Eq for Data<'a>[src]
impl From<&'static [u8; 0]> for Data<'_>[src]
impl From<&'static [u8; 1]> for Data<'_>[src]
impl From<&'static [u8; 2]> for Data<'_>[src]
impl From<&'static [u8; 3]> for Data<'_>[src]
impl From<&'static [u8; 4]> for Data<'_>[src]
impl<'a> Hash for Data<'a>[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl<'a> PartialEq<Data<'a>> for Data<'a>[src]
impl<'a> StructuralEq for Data<'a>[src]
impl<'a> StructuralPartialEq for Data<'a>[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Data<'a>
impl<'a> Send for Data<'a>
impl<'a> Sync for Data<'a>
impl<'a> Unpin for Data<'a>
impl<'a> UnwindSafe for Data<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,