Struct flipdot_core::Data[][src]

pub struct Data<'a>(_);

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]

Returns a reference to the inner Cow<[u8]>.

Examples

let data = Data::try_new(vec![])?;
assert!(data.get().is_empty());

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.