GithubHelp home page GithubHelp logo

Expose a DateTime type? about httpdate HOT 9 CLOSED

pyfisch avatar pyfisch commented on August 28, 2024
Expose a DateTime type?

from httpdate.

Comments (9)

pyfisch avatar pyfisch commented on August 28, 2024

Hi, I want to hide DateTime as an implementation detail and only use the standard SystemTime. Avoiding the allocated string would be good. I could either provide a function like this:

pub fn format_http_date(f: &mut fmt::Formatter, d: SystemTime) -> fmt::Result {
    DateTime::from(d).fmt(f)
}

It avoids the intermediate string but it can only be called if you already have a formatter. The alternative would be a type pub struct HttpDate (SystemTime} and implement FromStr and Display for it. Do you know if the smaller size of DateTime actually makes a difference?

from httpdate.

tailhook avatar tailhook commented on August 28, 2024

Well, the tokio's structures are generally quite large. And sure, 16 bytes vs 8 bytes of timestamp does not matter here.

Still I'm not sure why you want a yet another wrapper. There is no need to expose any methods or internal structure of DateTime except FromStr, Display, From, Into and perhaps a PartialOrd. So both options will look the same from the point of view of a user.

from httpdate.

pyfisch avatar pyfisch commented on August 28, 2024

There is no need to expose any methods or internal structure of DateTime except FromStr, Display, From, Into and perhaps a PartialOrd. So both options will look the same from the point of view of a user.

Ah good idea. So parse_http_date would return an opaque DateTime and can be converted to a SystemTime if necessary. It can also be formatted with Display. Maybe DateTime is too generic would you agree to name it HttpTime?

from httpdate.

tailhook avatar tailhook commented on August 28, 2024

Yes HttpTime sounds good.

from httpdate.

pyfisch avatar pyfisch commented on August 28, 2024

While editing the code I noticed that the crate is called httpdate but the type would be named HttpTime. Either I need to rename the crate and yank the old version or I should call it HttpDate.

from httpdate.

tailhook avatar tailhook commented on August 28, 2024

For that matter, I think HttpDate is equally meaningful as HttpTime :)

from httpdate.

pyfisch avatar pyfisch commented on August 28, 2024

Sorry for the delay, can you please have a look at the publicdate branch? I will release it after your review.

from httpdate.

tailhook avatar tailhook commented on August 28, 2024

Looks good. Thanks!

from httpdate.

pyfisch avatar pyfisch commented on August 28, 2024

Published as v0.3.0

from httpdate.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.