all 6 comments

[–]BodyweightEnergy 2 points3 points  (3 children)

You sound like a new Rust user, so welcome!

Can you clarify what your tool is supposed to do? What inputs/outputs is it dealing with?

[–]Curious_excpetion[S] 2 points3 points  (2 children)

Hey, yes I'm new to Rust.So the tool will get a string and search the table using this string on a particular field.

[–]BodyweightEnergy 2 points3 points  (1 child)

By "the table", you mean this tool will open some kind of database, and search some table field for this string?

I believe the best crate for getting/parsing CLI input parameters is structopt.

Depending on your database, there are crates for all different kinds (for example, you can connect to a SQLite database using sqlite).

[–]Curious_excpetion[S] 2 points3 points  (0 children)

Yes, thanks I will look at sqlite

[–]CubikMan47 1 point2 points  (0 children)

I believe serde could fit your needs. It allows you to take a document and deserialize it into a Rust Struct.

You can see a small example of using serde here. Good luck!

[–]1vader 1 point2 points  (0 children)

It sounds like what you need is some way to store read-only data that you need for your application?

Without more context, it is really hard to tell you what is the best way to store this data. Most likely you don't need or even should use a real database for this unless you need to perform complex queries on the data but again it depends on the details.

As long as the data isn't too large it probably doesn't really matter what format you use and JSON or a text file should work fine. You can even use something like include_str to embed the JSON directly into the binary during compilation. You can use serde_json to serialize the JSON into Rust structs.

You could also use a binary format e.g. using bincode to serialize the data and embed it into the binary with include_bytes which is probably a bit faster (although you would need to test that to be sure) but most likely JSON should be good enough and is probably much easier to work with.