Enum simple_text_editor::ops::Operation[][src]

pub enum Operation<'a> {
    Append(&'a str),
    Delete(usize),
    Print(usize),
    Undo,
    Invalid,
}

Contains all possible operations, as interpreted from commands via input. Invalid is a catch-all for any unrecognized commands.

Variants

Append(&'a str)

The append command, denotated by 1 in the program's input. The associated &'a str contains the string data to be appended to the buffer.

use simple_text_editor::ops::*;
let op = "1 append this text".into();
match op {
    Operation::Append(val) => {
        assert_eq!(val, "append this text");
    }
    _ => panic!("should have matched Operation::Append"),
}
Delete(usize)

The delete command, denotated by 2 in the program's input. The associated usize is the number of characters to be delete from the back of the buffer.

use simple_text_editor::ops::*;
let op = "2 5".into();
match op {
    Operation::Delete(n) => {
        assert_eq!(n, 5);
    }
    _ => panic!("should have matched Operation::Delete"),
}
Print(usize)

The print command, denotated by 3 in the program's input. The associated usize is the 1-based index at which the character from the buffer should be printed.

use simple_text_editor::ops::*;
let op = "3 1".into();
match op {
    Operation::Print(i) => {
        assert_eq!(i, 1);
    }
    _ => panic!("should have matched Operation::Print"),
}
Undo

The undo command, denotated by 4 in the program's input. There is no associated data, and thus simply pops a command from a maintained stack of undo-eligible operations, either being append or delete.

use simple_text_editor::ops::*;
let op = "4".into();
match op {
    Operation::Undo => {
        assert!(true);
    }
    _ => panic!("should have matched Operation::Undo"),
}
Invalid

Invalid is a catch-all for any unrecognized commands, and is ignored by the program.

use simple_text_editor::ops::*;
let op = "__BADOPERATION__".into();
match op {
    Operation::Invalid => {
        assert!(true);
    }
    _ => panic!("should have matched Operation::Invalid"),
}

Trait Implementations

impl<'a> Clone for Operation<'a>[src]

impl<'a> Debug for Operation<'a>[src]

impl<'a> From<&'a str> for Operation<'a>[src]

Convert a line of input into an Operation.

use simple_text_editor::ops::*;
let op = "1 abc".into();
assert!(matches!(op, Operation::Append("abc")));

impl<'a> PartialEq<Operation<'a>> for Operation<'a>[src]

impl<'a> StructuralPartialEq for Operation<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Operation<'a>[src]

impl<'a> Send for Operation<'a>[src]

impl<'a> Sync for Operation<'a>[src]

impl<'a> Unpin for Operation<'a>[src]

impl<'a> UnwindSafe for Operation<'a>[src]

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.