struct MementoContext {
undo_list: Vec<Memento>,
}
Expand description
This struct creates a context around the undo list that the memento_exercise() executes within. This gets around the problem of needing a static undo list as all the methods on this context have ready access to the undo list in the context.
Fields§
§undo_list: Vec<Memento>
The list of memento objects that form a series of snapshots in time of a MementoTextObject.
Implementations§
source§impl MementoContext
impl MementoContext
sourcefn new() -> MementoContext
fn new() -> MementoContext
Constructor.
sourcefn save_for_undo(&mut self, text_object: &MementoTextObject, operation: &str)
fn save_for_undo(&mut self, text_object: &MementoTextObject, operation: &str)
Take a snapshot of the given text object associated with the name of given operation.
Parameters
-
text_object
The MementoTextObject to take a snapshot of.
-
operation
A string describing the operation that will be applied after the snapshot is taken.
sourcefn operation_replace(
&mut self,
text_object: &mut MementoTextObject,
search_pattern: &str,
replace_text: &str
)
fn operation_replace( &mut self, text_object: &mut MementoTextObject, search_pattern: &str, replace_text: &str )
An operation to search and replace text in a MementoTextObject.
Parameters
-
text_object
The MementoTextObject to work with.
-
search_pattern
What to look for in the MementoTextObject
-
replace_text
What to replace the
search_pattern
with
sourcefn operation_reverse(&mut self, text_object: &mut MementoTextObject)
fn operation_reverse(&mut self, text_object: &mut MementoTextObject)
An operation to reverse the characters in the given MementoTextObject.
Parameters
-
text_object
The MementoTextObject to work with.
sourcefn undo(&mut self, text_object: &mut MementoTextObject)
fn undo(&mut self, text_object: &mut MementoTextObject)
Perform an undo on the given Command_TextObject, using the mementos in the “global” undo list. If the undo list is empty, nothing happens.
Parameters
-
text_object
The MementoTextObject to update.
sourcefn apply_replace_operation(
&mut self,
text_object: &mut MementoTextObject,
search_pattern: &str,
replace_text: &str
)
fn apply_replace_operation( &mut self, text_object: &mut MementoTextObject, search_pattern: &str, replace_text: &str )
Helper function to replace a pattern with another string in the given MementoTextObject after adding a snapshot of the text object to the undo list. Finally, it shows off what was done.
Parameters
-
text_object
The MementoTextObject to update.
-
search_pattern
What to look for in the MementoTextObject
-
replace_text
What to replace the
search_pattern
with
sourcefn apply_reverse_operation(&mut self, text_object: &mut MementoTextObject)
fn apply_reverse_operation(&mut self, text_object: &mut MementoTextObject)
Helper function to reverse the order of the characters in the given MementoTextObject after adding a snapshot of the text object to an undo list. Finally, it shows what was done.
Parameters
-
text_object
The MementoTextObject to work with.