pub struct Stack(/* private fields */);Expand description
Represent the stack file on disk.
Implementations§
Source§impl Stack
impl Stack
Sourcepub fn new(file: &str) -> Result<Self, PathError>
pub fn new(file: &str) -> Result<Self, PathError>
Creates a Stack object wrapping the supplied file.
§Errors
- Return
PathError::FilenameMissingif thefilehas no filename. - Return
PathError::InvalidPathif the path part offileis not a valid path. - Return
PathError::InvalidStackPathif stack path is invalid.
Sourcepub fn open(&self) -> Result<File, PathError>
pub fn open(&self) -> Result<File, PathError>
Open the stack file for reading, return a File.
§Errors
- Return
PathError::FileAccessif unable to open the file.
Sourcepub fn clear(&self) -> Result<(), PathError>
pub fn clear(&self) -> Result<(), PathError>
Truncates the stack file, removing all items from the stack.
§Errors
- Return
PathError::FileAccessif the stack file is not accessible.
Sourcepub fn push(&self, task: &str) -> Result<(), PathError>
pub fn push(&self, task: &str) -> Result<(), PathError>
Adds a new event to the stack file.
§Errors
- Return
PathError::FileAccessif the stack file cannot be opened or created. - Return
PathError::FileWriteif the stack file cannot be written.
Sourcepub fn pop(&self) -> Option<String>
pub fn pop(&self) -> Option<String>
Remove the most recent task from the stack file and return the task string.
Sourcepub fn drop(&self, arg: u32) -> Result<()>
pub fn drop(&self, arg: u32) -> Result<()>
Remove one or more tasks from the stack file.
If arg is 0, remove one item.
If arg is a positive number, remove that many items from the stack.
§Errors
- Return
Error::StackPopif attempts to pop more items than exist in the stack file.
Sourcepub fn keep(&self, num: u32) -> Result<()>
pub fn keep(&self, num: u32) -> Result<()>
Remove everything except the top num tasks from the stack.
§Errors
- Return
PathError::FileAccessif the stack file cannot be opened or created. - Return
PathError::FileWriteif the stack file cannot be written. - Return
PathError::RenameFailureif the stack file cannot be renamed.
Sourcepub fn process_down_stack<F>(&self, func: F) -> Result<()>
pub fn process_down_stack<F>(&self, func: F) -> Result<()>
Process the stack top-down, passing the index and lines to the supplied function.
§Errors
- Return
PathError::FileAccessif the stack file cannot be opened or created. - Return
PathError::FileWriteif the stack file cannot be written. - Return
PathError::RenameFailureif the stack file cannot be renamed.
Sourcepub fn list(&self) -> String
pub fn list(&self) -> String
Format the stack as a String.
The stack will be formatted such that the most recent item is listed first.
Sourcepub fn top(&self) -> Result<String>
pub fn top(&self) -> Result<String>
Return the top of the stack as a String.
§Errors
- Return
PathError::FileAccessif the stack file cannot be opened or created. - Return
PathError::FileWriteif the stack file cannot be written. - Return
PathError::RenameFailureif the stack file cannot be renamed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Stack
impl RefUnwindSafe for Stack
impl Send for Stack
impl Sync for Stack
impl Unpin for Stack
impl UnwindSafe for Stack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more