Operation

Enum Operation 

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

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§

Source§

impl<'a> Clone for Operation<'a>

Source§

fn clone(&self) -> Operation<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Operation<'a>

Source§

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

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

impl<'a> From<&'a str> for Operation<'a>

Convert a line of input into an Operation.

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

fn from(input: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for Operation<'a>

Source§

fn eq(&self, other: &Operation<'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> StructuralPartialEq for Operation<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Operation<'a>

§

impl<'a> RefUnwindSafe for Operation<'a>

§

impl<'a> Send for Operation<'a>

§

impl<'a> Sync for Operation<'a>

§

impl<'a> Unpin for Operation<'a>

§

impl<'a> UnwindSafe for Operation<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.