mikrotik_rs::protocol::word

Enum Word

Source
pub enum Word<'a> {
    Category(WordCategory),
    Tag(u16),
    Attribute(WordAttribute<'a>),
    Message(&'a str),
}
Expand description

Represents a word in a Mikrotik [Sentence].

Words can be of three types:

  • A category word, which represents the type of sentence, such as !done, !re, !trap, or !fatal.
  • A tag word, which represents a tag value like .tag=123.
  • An attribute word, which represents a key-value pair like =name=ether1.

The word can be converted into one of these types using the TryFrom trait.

§Examples

use mikrotik::command::reader::Word;

let word = Word::try_from(b"=name=ether1");
assert_eq!(word.unwrap().attribute(), Some(("name", Some("ether1"))));

Variants§

§

Category(WordCategory)

A category word, such as !done, !re, !trap, or !fatal.

§

Tag(u16)

A tag word, such as .tag=123.

§

Attribute(WordAttribute<'a>)

An attribute word, such as =name=ether1.

§

Message(&'a str)

An unrecognized word. Usually this is a !fatal reason message.

Implementations§

Source§

impl Word<'_>

Source

pub fn category(&self) -> Option<&WordCategory>

Returns the category of the word, if it is a category word.

Source

pub fn tag(&self) -> Option<u16>

Returns the tag of the word, if it is a tag word.

Source

pub fn attribute(&self) -> Option<(&str, Option<&str>)>

Returns the attribute of the word, if it is an attribute word.

Source

pub fn generic(&self) -> Option<&str>

Returns the generic word, if it is a generic word. This is usually a !fatal reason message.

Source

pub fn word_type(&self) -> WordType

Returns the type of the Word.

Trait Implementations§

Source§

impl<'a> Debug for Word<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Word<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Word<'_>> for WordType

Source§

fn from(word: Word<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Word<'a>

Source§

fn eq(&self, other: &Word<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> TryFrom<&'a [u8]> for Word<'a>

Source§

type Error = WordError

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

fn try_from(value: &'a [u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> StructuralPartialEq for Word<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Word<'a>

§

impl<'a> RefUnwindSafe for Word<'a>

§

impl<'a> Send for Word<'a>

§

impl<'a> Sync for Word<'a>

§

impl<'a> Unpin for Word<'a>

§

impl<'a> UnwindSafe for Word<'a>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.