Comments (5)
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.
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.
The generator will likely use an algorithm similar to:
- Create a new
DateTime
using the chrono library - Compare that with the last ulid's datetime to see if it's in the same millisecond (see
Ulid::datetime()
) - 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
- If an overflow occurs,
- 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.
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.
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)
- doc suggestion: use generator in quickstart guide?
- Consider lib upgrade HOT 1
- UUIDv7 conversions HOT 1
- Investigate chrono -> time perf regressions HOT 1
- Recommended Storage For MySQL and Postgres HOT 2
- v0.6 WASM runtime error: 'time not implemented on this platform' HOT 11
- What's the difference between this and rusty_ulid? HOT 2
- Unable to compile the combination of `no_std` and the `serde` feature
- Is there a method to validate that a ULID is valid? HOT 1
- Figure out what to do with overflowing ulid values
- Add MAX and MIN Ulid values
- Expose base32 implementation? HOT 2
- postgres traits HOT 1
- to_str variable buffer size HOT 1
- [FEATURE] SQLx support HOT 1
- Infallible `Generator` generation HOT 2
- web_time resolve error with --target wasm32-wasi HOT 2
- CVEs in CLI HOT 1
- Add support for Encode and Decode traits from both bincode and bitcode
- Generator doesn't actually guarantee 80-bits of UIDs per millisecond? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ulid-rs.