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

Extended timestamp returns Option<&u32>, which could be copied instead (so Option<u32>) #183

Closed
zeichenreihe opened this issue Jun 3, 2024 · 0 comments
Labels
enhancement New feature or request fix merged Fix is merged, but the issue will stay open until it's released.

Comments

@zeichenreihe
Copy link

Is your feature request related to a problem? Please describe.
So I'm getting the modification times of a file inside a zip file, with the methods here:

/// returns the last modification timestamp
pub fn mod_time(&self) -> Option<&u32> {
self.mod_time.as_ref()
}
/// returns the last access timestamp
pub fn ac_time(&self) -> Option<&u32> {
self.ac_time.as_ref()
}
/// returns the creation timestamp
pub fn cr_time(&self) -> Option<&u32> {
self.cr_time.as_ref()
}

It's annoying to have to deal with Option<&u32>. In some cases you need to deref it (so something like if let Some(x) = file.ac_time() { let time = *x; ... }), or you need to use .copied() to convert Option<&u32> into Option<u32>.

Describe the solution you'd like
I think it would be better to have this api return Option<u32>, since u32 is easily copyable.
One way would be to have methods like

/// returns the last modification timestamp 
pub fn modification_time(&self) -> Option<u32> { 
    self.mod_time
} 
 
/// returns the last access timestamp 
pub fn access_time(&self) -> Option<u32> { 
    self.ac_time
} 
 
/// returns the creation timestamp 
pub fn creation_time(&self) -> Option<u32> { 
    self.cr_time
}

Describe alternatives you've considered
The alternative to this is to put use x.cr_time().copied(), instead of the proposed x.creation_time().

Another idea would be to have these return some struct encapsulating the fact that it's actually an unix timestamp that's stored here. This struct would look like UnixTimestamp(u32), and would also #[derive(Copy)].

Another idea would be to have a proper time type, from some other crate (chrono?).

@zeichenreihe zeichenreihe added the enhancement New feature or request label Jun 3, 2024
@Pr0methean Pr0methean added the fix merged Fix is merged, but the issue will stay open until it's released. label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix merged Fix is merged, but the issue will stay open until it's released.
Projects
None yet
Development

No branches or pull requests

2 participants