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
impl MementoTextObject
sourcepub fn new(text: &str) -> MementoTextObject
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.
sourcepub fn get_memento(&self, operation_name: &str) -> Memento
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.
sourcepub fn restore_memento(&mut self, memento: &Memento)
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.