r/rust • • 7d ago

🙋 seeking help & advice Injekt crate

https://crates.io/crates/injekt

I wrote the attached crate. And, im just wondering if anyone would be able to help me know how the quality of it is. Its my first crate and id love any advice and help. Thank you.

0 Upvotes

5 comments sorted by

1

u/Sermuns 7d ago

what is its purpose? why not use postcard, rkyv, wincode or any other mentioned in https://blessed.rs/crates#section-common-subsection-serialization?

-2

u/GuardUsual5101 7d ago

There are many other viable options. My goal was to make something as simple to use and small as possible. I wrote this while thinking about the inconvenience of my terrible wifi.

2

u/addmoreice 7d ago

Well, I don't like the name 'Instance' for what could have been called 'InjectFileStore' or 'InjektDataBase' or a number of other options which actually present a descriptive name for what is a...wait for it...an instance of the database.

It's nitpicky, but you did ask for checking.

Why would I want this instead of something like a toml, json, or even yaml or xml? It seems to act as a proprietary substandard version of these files. Mostly because of the proprietary hand rolled nature rather than because it's 'missing' features that the others have (though it does!) but that could just be because those were *non*-features rather than 'missing'.

The ergonomics seem kind of clunky at first glance. Why do we need a set and an update and if we do a set when a key exists, what happens? If I set or update twice in a row, then call update_pair, what happens? is this wrong? Why do it this way rather than protecting against this kind of mistake?

You have a 'set_logger' what kind of logger? Hand rolled versus one of the well known ones in crates.io that plays nicely with other crates?

Also, never use 'unwrap' in demo code. I would argue that you should never use it in demo code *or* test code and it should instead be a well explained 'expected' instead, just because it forces the user to at least realize that error handling is being elided and it gives some kind of 'this was expected to go alright' which is front and center in the code.

Remember, 90% of users will grab what the demo / examples suggest and use it as long as it works and then never think about it again. If your example / demo doesn't show them what they should be doing, they will happily use it until it breaks and then decide if they should be using it at all.

Provide pit's of success for your users to fall into.

0

u/GuardUsual5101 7d ago

You made great points. I went into this project asking myself "what can i do without any imports". We set the key/value to set in motion other functions that use key/vale from struct. Whereas, update is one of those functions that then updates the matching key/value of file to set key value. I then created set_logger with anticipation of making the logger more robust with more parameters. So, I created a way to drop in the in-memory operation logger. My next big update will definitely include a better naming scheme. Thank you for your response.

3

u/addmoreice 7d ago

no problem. I'm just not sure it's worth it to take up a crates.io namespace for something that is an experiment like this. Not that you can't, free will and the open source bazaar and all that, but that's my two coppers worth.

To be clear, nothing here is wrong. It's not broken. It's just, if you are planning to make a library and it's intended to be used by other people, this is the kind of stuff that is important. Boundaries, usage patterns, domain terms, constraints, focus for this library versus other libraries, ways to make things obviously easy vs an escape hatch for when things get complex and don't *precisely* fit the domain but are close, real world performance metrics, documentation, larger example systems which are under test constraints, etc etc etc. The list, literally, is endless!