Coder Social home page Coder Social logo

rust-ksuid's People

Contributors

aurelien-clu avatar mrl5 avatar nilium avatar tasn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rust-ksuid's Issues

Make ksuid hashable so it can be used within HashSet & HashMap

Feature Request

Motivation

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);
    }
}

Proposal

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:

  • simple
  • not prone to bugs or hash collisions (not more than ksuid as far as my understanding)

Alternatives

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 ๐Ÿ˜‡

Next

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 ๐Ÿ˜„

Serde feature missing

Bug Report

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?

Version

svix-ksuid v0.6.0

Platform

Linux antiva 6.1.12-1-MANJARO #1 SMP PREEMPT_DYNAMIC Tue Feb 14 21:59:10 UTC 2023 x86_64 GNU/Linux

Description

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

Implement `Display` for `svix_ksuid::Ksuid`

Feature Request

Motivation

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.

Proposal

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?

Alternatives

N/A

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.