Code Monkey home page Code Monkey logo

Comments (5)

dylanhart avatar dylanhart commented on May 31, 2024

Hi! Thank you for your contribution. You're right that this isn't currently implemented; It wasn't in the spec when this project was created. This will likely be implemented with adding a Generator/Factory struct to the library that can store the state of the last ulid created.

Is this something you wanted to implement, or that you have an immediate need for?

from ulid-rs.

camerondavison avatar camerondavison commented on May 31, 2024

I don't have any real immediate need. I may try and put together a pull request for it. Unsure if I will have time. Do you have any other architecture suggestions besides having a generator that keeps track of the last ulid?

from ulid-rs.

dylanhart avatar dylanhart commented on May 31, 2024

The generator will likely use an algorithm similar to:

  1. Create a new DateTime using the chrono library
  2. Compare that with the last ulid's datetime to see if it's in the same millisecond (see Ulid::datetime())
  3. If it's within the same millisecond call Ulid::increment() to get a monotonic ulid. (needs implementation, signature: fn increment(&self) -> Option<Ulid>)
    • If an overflow occurs, None will be returned
  4. Otherwise use Ulid::from_datetime() to create a new Ulid
struct Generator {
    previous: Option<Ulid>;
}

impl Generator {
    fn new() -> Generator { ... }
    fn generate(&mut self) -> Result<Ulid, MontonicError> { ... }
}

enum MonotonicError {
    Overflow,
}

from ulid-rs.

dylanhart avatar dylanhart commented on May 31, 2024

I'll assign this to you for the next week. If you don't get around to it, it's no big deal.

from ulid-rs.

camerondavison avatar camerondavison commented on May 31, 2024

I found some time this afternoon, and it was easier to knock out than expected. of course if this is not the direction you were expecting then I can change it up.

If you do like it then I can work on putting documentation in the readme as part of the pull request as well.

from ulid-rs.

Related Issues (20)

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.