morse_codec::message

Struct Message

source
pub struct Message<const MSG_MAX: usize> { /* private fields */ }

Implementations§

source§

impl<const MSG_MAX: usize> Message<MSG_MAX>

source

pub fn new(message_str: &str, edit_pos_end: bool) -> Self

Get an instance of Message starting from an &str.

edit_pos_end means client code wants to continue editing this text at the end.

source§

impl<const MSG_MAX: usize> Message<MSG_MAX>

source

pub fn iter(&self) -> MessageIterator<'_, MSG_MAX>

Get an iterator to the message text contained within.

source

pub fn set_edit_pos(&mut self, pos: usize)

Sets current editing position to given value.

source

pub fn get_edit_pos(&self) -> usize

Returns current editing position.

source

pub fn shift_edit_left(&mut self)

Move editing position to the left.

source

pub fn shift_edit_right(&mut self)

Move editing position to the right.

source

pub fn add_char(&mut self, ch: u8)

Insert character at the editing position.

If any characters before the character are FILLER_BYTEs They’ll automatically be converted to empty characters ’ ’ which means the user wants some space between words.

source

pub fn put_char_at(&mut self, index: usize, ch: u8)

Insert character at index.

If any characters before the character are FILLER_BYTEs They’ll automatically be converted to empty characters ’ ’ which means the user wants some space between words.

source

pub fn char_at(&self, index: usize) -> &u8

Returns character at an index as a byte

source

pub fn len(&self) -> usize

Returns current length of the message discarding empty FILLER_BYTE characters at the end.

This is useful for creating ranged loops of actual characters decoded or can be encoded.

source

pub fn is_empty(&self) -> bool

Returns true if the message is empty, false otherwise.

This method discards FILLER_BYTE characters and only takes into account normal characters.

source

pub fn set_message( &mut self, message_str: &str, edit_pos_end: bool, ) -> Result<(), &str>

Manually set the message from an &str.

edit_pos_end flag means we’ll continue from the end of this string when we continue decoding or encoding.

source

pub fn as_bytes(&self) -> [u8; MSG_MAX]

Returns the message as it is now in a byte array format.

Note that this also includes ‘empty’ FILLER_BYTE characters. Client code can use return value of len() which is the actual length to loop through it or filter the fillers manually in a loop or iterator.

source

pub fn as_str(&self) -> &str

Returns the message as it is now as &str slice.

Note that this does not include empty FILLER_BYTE characters.

source

pub fn clear(&mut self)

Clear the message and start over.

Trait Implementations§

source§

impl<const MSG_MAX: usize> Default for Message<MSG_MAX>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const MSG_MAX: usize> Freeze for Message<MSG_MAX>

§

impl<const MSG_MAX: usize> RefUnwindSafe for Message<MSG_MAX>

§

impl<const MSG_MAX: usize> Send for Message<MSG_MAX>

§

impl<const MSG_MAX: usize> Sync for Message<MSG_MAX>

§

impl<const MSG_MAX: usize> Unpin for Message<MSG_MAX>

§

impl<const MSG_MAX: usize> UnwindSafe for Message<MSG_MAX>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.