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

Review relationship between Datetime and Timezone #7

Open
maximelenoir opened this issue Sep 15, 2016 · 0 comments
Open

Review relationship between Datetime and Timezone #7

maximelenoir opened this issue Sep 15, 2016 · 0 comments

Comments

@maximelenoir
Copy link
Owner

A Datetime basically bundles a Timespec and a Timezone together:

pub struct Datetime<'a> {
    tz: &'a Timezone,
    stamp: Timespec,
}

The reference is annoying because it pollutes the type (and everything using it) with a lifetime and by binding the Datetime to its Timezone, making it difficult to move the Datetime around. Other solutions exist to circumvent this issue, although none of them seems to really stand out.

Type Pros Cons
reference Sharable between Datetimes Makes Datetime difficult to move around; lifetime pollution
owned Straightforward Timezone is moved on Datetime creation; would need to clone when creating several Datetimes with the same Timezone
Rc Easily shared between multiple Datetimes Ref count overhead
Arc Easily shared between multiple Datetimes; cross thread boundaries Ref count overhead

Another solution would be to actually let the user choose the adequate solution through the use of the Borrow trait. Although I haven't dig deep on this solution, I believe it would be awkward to use because of the way the current API is written i.e. Timezone creates Datetime. If the calls were reversed i.e. a Datetime is created from a Timezone and some parameters (e.g. unix timestamp, date, ...) then Borrow would become usable.

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