refactoring

This commit is contained in:
2025-01-06 20:51:54 -05:00
parent edced4ddf1
commit 9f0a376d5e
8 changed files with 133 additions and 109 deletions

View File

@ -1,8 +1,22 @@
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub mod session;
pub mod commands;
pub mod ps;
pub mod rc;
pub mod vm;
pub mod vm;
pub trait MapDisplay<T, E: std::fmt::Display> {
fn map_or_display<F: FnOnce(T)>(self, f: F);
fn map_or_display_none<R, F: FnOnce(T) -> Option<R>>(self, f: F) -> Option<R>;
}
impl<T, E: std::fmt::Display> MapDisplay<T, E> for Result<T, E> {
///Map and display an error
#[inline]
fn map_or_display<F: FnOnce(T)>(self, f: F) {
self.map_or_else(|e| color_print::ceprintln!("<bold,r>[!]:</> {e}"), f)
}
///Map and display an error but return `None`
#[inline]
fn map_or_display_none<R, F: FnOnce(T) -> Option<R>>(self, f: F) -> Option<R> {
self.map_or_else(|e| { color_print::ceprintln!("<bold,r>[!]:</> {e}"); None }, f)
}
}