pub struct Stack(_);
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::FilenameMissing
if thefile
has no filename. - Return
PathError::InvalidPath
if the path part offile
is not a valid path. - Return
PathError::InvalidStackPath
if 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::FileAccess
if 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::FileAccess
if 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::FileAccess
if the stack file cannot be opened or created. - Return
PathError::FileWrite
if 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::StackPop
if 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::FileAccess
if the stack file cannot be opened or created. - Return
PathError::FileWrite
if the stack file cannot be written. - Return
PathError::RenameFailure
if the stack file cannot be renamed.
sourcepub fn process_down_stack<F>(&self, func: F) -> Result<()>where
F: FnMut(usize, &str),
pub fn process_down_stack<F>(&self, func: F) -> Result<()>where F: FnMut(usize, &str),
Process the stack top-down, passing the index and lines to the supplied function.
Errors
- Return
PathError::FileAccess
if the stack file cannot be opened or created. - Return
PathError::FileWrite
if the stack file cannot be written. - Return
PathError::RenameFailure
if 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::FileAccess
if the stack file cannot be opened or created. - Return
PathError::FileWrite
if the stack file cannot be written. - Return
PathError::RenameFailure
if the stack file cannot be renamed.
Trait Implementations§
Auto Trait Implementations§
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