pub struct ShortFrame { /* private fields */ }Expand description
A fixed-length short frame.
Implementations§
Source§impl ShortFrame
impl ShortFrame
Sourcepub const fn new(
control: Control,
address: Address,
) -> Result<Self, ShortFrameError>
pub const fn new( control: Control, address: Address, ) -> Result<Self, ShortFrameError>
Creates a validated short frame.
Examples found in repository?
More examples
Sourcepub const fn control(&self) -> Control
pub const fn control(&self) -> Control
Returns the control field.
Examples found in repository?
examples/decode_exact_alloc.rs (line 22)
17fn main() -> Result<(), DecodeError> {
18 let frame = decode(&[0x10, 0x5b, 0x01, 0x5c, 0x16])?;
19
20 if let Frame::Short(short) = &frame {
21 assert_eq!(
22 short.control().communication_type(),
23 CommunicationType::ReqUd2
24 );
25 assert_eq!(short.address().value(), 1);
26 }
27
28 assert_eq!(frame.encode(), [0x10, 0x5b, 0x01, 0x5c, 0x16]);
29 Ok(())
30}More examples
examples/decode_exact_no_alloc.rs (line 22)
17fn main() -> Result<(), DecodeError> {
18 let frame = decode(&[0x10, 0x5b, 0x01, 0x5c, 0x16])?;
19
20 if let Frame::Short(short) = &frame {
21 assert_eq!(
22 short.control().communication_type(),
23 CommunicationType::ReqUd2
24 );
25 assert_eq!(short.address().value(), 1);
26 }
27
28 let mut output = [0_u8; LongFrame::MAX_LEN];
29 assert_eq!(
30 frame
31 .encode_into(&mut output)
32 .expect("maximum frame buffer is large enough"),
33 [0x10, 0x5b, 0x01, 0x5c, 0x16]
34 );
35
36 Ok(())
37}Sourcepub const fn address(&self) -> Address
pub const fn address(&self) -> Address
Returns the address field.
Examples found in repository?
examples/decode_exact_alloc.rs (line 25)
17fn main() -> Result<(), DecodeError> {
18 let frame = decode(&[0x10, 0x5b, 0x01, 0x5c, 0x16])?;
19
20 if let Frame::Short(short) = &frame {
21 assert_eq!(
22 short.control().communication_type(),
23 CommunicationType::ReqUd2
24 );
25 assert_eq!(short.address().value(), 1);
26 }
27
28 assert_eq!(frame.encode(), [0x10, 0x5b, 0x01, 0x5c, 0x16]);
29 Ok(())
30}More examples
examples/decode_exact_no_alloc.rs (line 25)
17fn main() -> Result<(), DecodeError> {
18 let frame = decode(&[0x10, 0x5b, 0x01, 0x5c, 0x16])?;
19
20 if let Frame::Short(short) = &frame {
21 assert_eq!(
22 short.control().communication_type(),
23 CommunicationType::ReqUd2
24 );
25 assert_eq!(short.address().value(), 1);
26 }
27
28 let mut output = [0_u8; LongFrame::MAX_LEN];
29 assert_eq!(
30 frame
31 .encode_into(&mut output)
32 .expect("maximum frame buffer is large enough"),
33 [0x10, 0x5b, 0x01, 0x5c, 0x16]
34 );
35
36 Ok(())
37}Sourcepub fn decode(bytes: &[u8]) -> Result<Self, ShortFrameError>
pub fn decode(bytes: &[u8]) -> Result<Self, ShortFrameError>
Decodes exactly one short frame.
Sourcepub fn encode_into<'a>(
&self,
output: &'a mut [u8],
) -> Result<&'a [u8], ShortFrameError>
pub fn encode_into<'a>( &self, output: &'a mut [u8], ) -> Result<&'a [u8], ShortFrameError>
Encodes the frame into output and returns the encoded portion.
Trait Implementations§
Source§impl Clone for ShortFrame
impl Clone for ShortFrame
Source§fn clone(&self) -> ShortFrame
fn clone(&self) -> ShortFrame
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ShortFrame
Source§impl Debug for ShortFrame
impl Debug for ShortFrame
impl Eq for ShortFrame
Source§impl From<ShortFrame> for Frame
impl From<ShortFrame> for Frame
Source§fn from(frame: ShortFrame) -> Self
fn from(frame: ShortFrame) -> Self
Converts to this type from the input type.
Source§impl Hash for ShortFrame
impl Hash for ShortFrame
Source§impl PartialEq for ShortFrame
impl PartialEq for ShortFrame
impl StructuralPartialEq for ShortFrame
Auto Trait Implementations§
impl Freeze for ShortFrame
impl RefUnwindSafe for ShortFrame
impl Send for ShortFrame
impl Sync for ShortFrame
impl Unpin for ShortFrame
impl UnsafeUnpin for ShortFrame
impl UnwindSafe for ShortFrame
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
Mutably borrows from an owned value. Read more