svix / rust-ksuid Goto Github PK
View Code? Open in Web Editor NEWA pure-Rust KSUID implementation
Home Page: https://www.svix.com
License: MIT License
A pure-Rust KSUID implementation
Home Page: https://www.svix.com
License: MIT License
I would like to use ksuid
within an HashMap<Ksuid/KsuidMs, T>
and I would prefer not to convert to a string, i.e. HashMap<String, T>
.
Right now I am wrapping it within a struct (I am not aware of a better way, like a macro to implicitly call to_string
before hashing):
use std::hash::{Hash, Hasher};
use svix_ksuid::Ksuid;
pub struct Id(pub Ksuid);
impl Hash for Id {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.to_string().hash(state);
}
}
I believe the following would be enough:
use std::hash::{Hash, Hasher};
impl Hash for Ksuid {
fn hash<H: Hasher>(&self, state: &mut H) {
self.to_string().hash(state);
}
}
impl Hash for KsuidMs {
fn hash<H: Hasher>(&self, state: &mut H) {
self.to_string().hash(state);
}
}
Pros:
Having an intermediate String before computing the hash is not the most efficient way to do this but I personally would prefer to have something even if it is not the most performant ๐
If you don't mind my proposal, would you like me to make a PR with it?
If you do mind adding this, fair enough, I will handle this on my end. ๐
If you do mind using the intermediate string, do you already have in mind a way to do it or would you like me to look into it? (my experience is limited)
Either way, thank you for the library ๐
The docs say there should be a feature enabling serde
support but cargo complains that there is no such feature.
I can't really tell if this has been removed or added as a permanent feature that's always on?
svix-ksuid v0.6.0
Linux antiva 6.1.12-1-MANJARO #1 SMP PREEMPT_DYNAMIC Tue Feb 14 21:59:10 UTC 2023 x86_64 GNU/Linux
Trying to add the crate ends up with:
git:(main) cargo add svix-ksuid --features serde
Updating crates.io index
Adding svix-ksuid v0.6.0 to dependencies.
error: unrecognized feature for crate svix-ksuid: serde
no features available for crate svix-ksuid
Hi! I'm not sure if this is intentional, but it looks like Ksuid
doesn't implement Display
.
This means that to print it out you need to do format!("{}", ksuid.to_string())
rather than just format!("{}", ksuid)
.
Not a big deal, but adds some verbosity.
Implementing Display
should be as simple as moving the existing to_string
logic into a Display
impl.
I'm not sure if the type doesn't implement Display
intentionally though. Perhaps this was done to avoid some API guarantees?
N/A
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.