x-hgg-x / tz-rs

A pure Rust reimplementation of libc functions localtime, gmtime and mktime.
Apache License 2.0
169 stars 5 forks source link

A full no_std implementation. #38

Closed darleybarreto closed 1 month ago

darleybarreto commented 2 months ago

Hi there,

Would you be interested in merging a contribution to make tz-rs full no_std?

I am asking this because I think this crate can help relibc a lot. For both Redox and Linux, we basically have all the necessary building blocks to use tz-rs, including logging etc.

What would be the best approach here? Having traits for everything that requires std and then implementing on relibc? And for those who can use std, nothing changes, just need to add boilerplate to current code.

Kind regards,

Darley

x-hgg-x commented 2 months ago

Would you be interested in merging a contribution to make tz-rs full no_std?

Yes this could be a good addition to the library.

The following methods are missing when the std feature is disabled :

What would be the best approach here? Having traits for everything that requires std and then implementing on relibc? And for those who can use std, nothing changes, just need to add boilerplate to current code.

A trait is a good idea, like in the following code:

pub trait StdImpl {
    fn new() -> Self;
    fn now() -> i64;
    // ...
    // define all needed methods
}

pub struct Std;

impl StdImpl for Std {
    fn new() -> Self {
        Self
    }
   // impl using std
}

pub struct GenericTimeZone<T: StdImpl> {
    // ...
    std: T
}

pub type TimeZone = GenericTimeZone<Std>;

Adding a new trait method afterwards will be a breaking change, so we should be careful when selecting needed methods.

darleybarreto commented 1 month ago

I see, thanks for the great feedback. I will give this a try.

darleybarreto commented 1 month ago

Hey, I'm not really a Rust expert, would you be able to expand more on your first comment? The pain points here are mostly the types directly used inside, so I'm having a hard time figuring this out properly.

x-hgg-x commented 1 month ago

This is more complex than it seems, I will try to do a first implementation myself.

x-hgg-x commented 1 month ago

Implemented in tz-rs v0.7.0.

darleybarreto commented 1 month ago

Wow, thank you soo much!!