Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Change Registry Function Pointer Types to Option<fn()> #21

Open
allaboutevemirolive opened this issue Aug 6, 2024 · 1 comment

Comments

@allaboutevemirolive
Copy link
Owner

For context: https://doc.rust-lang.org/beta/std/primitive.fn.html

pub struct Registry<'a> {
// Common util
read: FnReadDir,
sort: FnSortEntries,
// Entry
pub dir: FnOutDir<StdoutLock<'a>>,
pub file: FnOutFile<StdoutLock<'a>>,
pub symlink: FnOutSymlink<StdoutLock<'a>>,
pub head: FnOutHead<StdoutLock<'a>>,
// Metadata
pub pms: FnExtPermission<StdoutLock<'a>>,
pub btime: FnExtBTime<StdoutLock<'a>>,
pub mtime: FnExtModTime<StdoutLock<'a>>,
pub atime: FnExtAccessTime<StdoutLock<'a>>,
pub size: FnExtSize<StdoutLock<'a>>,
// Color
reset: FnColor<StdoutLock<'a>>,
yellow: FnColor<StdoutLock<'a>>,
bold_red: FnColor<StdoutLock<'a>>,
underlined_blue: FnColor<StdoutLock<'a>>,
blue: FnColor<StdoutLock<'a>>,
green: FnColor<StdoutLock<'a>>,
purple: FnColor<StdoutLock<'a>>,
}

@allaboutevemirolive allaboutevemirolive changed the title Make function pointer type of Option<fn()> Refactor: Change Registry Function Pointer Types to Option<fn()> Sep 14, 2024
@allaboutevemirolive
Copy link
Owner Author

I'm not convinced about this implementation. All fields will be called regardless of whether they're used, so wrapping the type in Option seems unnecessary.

The key difference is that using Option requires us to check or unwrap it for every folder iteration. Without Option, we can avoid these extra steps, either calling a function that performs an action or a no-op function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant