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

It is not possible to assign a Duration to a const variable #18166

Closed
carllerche opened this Issue Oct 19, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@carllerche
Copy link
Member

carllerche commented Oct 19, 2014

The struct fields are currently not pub making it impossible to assign Duration to a const variable.

Given that Duration is essentially timespec, it seems like it might be a good idea to make the struct fields public.

cc @aturon

@ben0x539

This comment has been minimized.

Copy link
Contributor

ben0x539 commented Oct 20, 2014

There's a legit timespec in liblibc by the way. I don't think the field sizes are compatible, though.

@Gankro

This comment has been minimized.

Copy link
Contributor

Gankro commented Oct 20, 2014

Can this wait for Compile Time Function Evaluation to be implemented properly? It seems like that would be the correct solution to this problem (unless having the fields public is otherwise desirable).

1-more added a commit to 1-more/rust that referenced this issue Nov 3, 2014

libstd’s Duration refactor
This commit changes the internal representation of Duration from

    pub struct Duraion {
        secs: i64,
        nanos: i32
    }

to

    /// An absolute amount of time, independent of time zones
    /// and calendars with tick precision. A single tick
    /// represents 100 nanoseconds.
    pub struct Duration(pub i64)

Closes rust-lang#18166,rust-lang#18416.

@steveklabnik steveklabnik added the A-libs label Jan 27, 2015

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 27, 2015

This is still true today.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 27, 2015

Sample program:

use std::time::Duration;

const MINUTE: Duration = Duration::new(60, 0);

fn main() {}

This is basically always going to be true until const fn is stable, since things are now stable, so there's not much we can really do here, so I'm giving this a close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.