pub struct MementoTextObject {
    text: String,
}
Expand description

Container for a string. Need to use a struct that allows the text to be changed while the container (this struct) remains constant. This way, operations can be applied to the text and the container’s contents change but not the container.

Fields§

§text: String

The text that can change in this MementoTextObject class.

Implementations§

source§

impl MementoTextObject

source

pub fn new(text: &str) -> MementoTextObject

Constructs a text object with an initial string.

Parameters
  • text

    The text that will be managed by this MementoTextObject.

Returns

Returns a new instance of the MementoTextObject struct.

source

pub fn text(&self) -> &str

Gets the text in this MementoTextObject.

source

pub fn set_text(&mut self, text: &str)

Sets the text in this MementoTextObject.

source

pub fn get_memento(&self, operation_name: &str) -> Memento

Returns a Memento object containing a snapshot of the text stored in this instance.

Parameters
  • operation_name

    The name of the memento to create. In this case, the name is the operation that is to be applied to the text object.

Returns

Returns an instance of the Memento struct, representing the snapshot of this MementoTextObject.

source

pub fn restore_memento(&mut self, memento: &Memento)

Sets the text in this MementoTextObject instance to the snapshot stored in the given Memento object (which is assumed to be from the MementoTextObject::get_memento() method).

Parameters
  • memento

    A Memento object containing the text that will be copied over the text in this MementoTextObject.

Trait Implementations§

source§

impl Display for MementoTextObject

source§

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

Converts the MementoTextObject to a string (makes it easier to use the struct in string formatting).

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V