morse_codec::message

Struct Message

Source
pub struct Message<const MSG_MAX: usize> { /* private fields */ }
Expand description

This struct holds the message in human readable format.

It also provides functions to do edit position manipulation, getting or setting characters at index positions.

Implementations§

Source§

impl<const MSG_MAX: usize> Message<MSG_MAX>

Source

pub const POS_MAX: usize

Maximum index editing position can be at

Source

pub fn new(message_str: &str, edit_pos_end: bool, clamp_edit_pos: 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 chars contained within.

Source

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

Sets current editing position to given value.

Source

pub fn set_edit_position_clamp(&mut self, clamp: bool)

Change the clamping behaviour of the edit position to wrapping (default) or clamping.

With clamping set, when edit position is shifted to left or right, it won’t cycle forward to maximum position or revert back to zero position, effectively remaining within the limits of the message no matter current position is.

Source

pub fn is_edit_clamped(&self) -> bool

Source

pub fn get_edit_pos(&self) -> usize

Returns current editing position.

Source

pub fn get_last_changed_index(&self) -> usize

Source

pub fn get_last_changed_char(&self) -> Character

Source

pub fn shift_edit_left(&mut self)

Move editing position to the left. By default it will wrap to the end if position is 0

Source

pub fn shift_edit_right(&mut self)

Move editing position to the right. By default it will wrap to the beginning if position is POS_MAX

Source

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

Insert character at the editing position.

If any characters before the character are FILLERs 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: Character) -> Result<(), &str>

Insert character at index.

If any characters before the character are FILLERs 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) -> Character

Returns character at an index

Source

pub fn len(&self) -> usize

Returns current length of the message discarding empty FILLER 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 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_charray(&self) -> [Character; MSG_MAX]

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

Note that this also includes ‘empty’ FILLER 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. Or as a [Utf8Charray] if “utf8” feature is enabled.

Note that this does not include empty FILLER 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.