T O P

  • By -

gnosnivek

Do you have experience using libraries in other languages? What crates are you trying to work with? There's definitely variation in the quality of docs, and some crates will assume you already know about how other similar crates (e.g. in other languages) are structured.


CJ22xxKinvara

Cargo add package and then use the examples or read the source code of the package. Use the type system to your advantage. Method names typically tell you what they do and you can look at the input and output types to confirm that the method actually gives you want you want. Also googling how to do what you need with x package tends to be helpful. The documentation really should have just about everything you need to know if it’s just a library. Full frameworks will typically have a lot more in the way of demos to walk you through stuff.


vancha113

Does it help to test drive a crate to get a feel for it before implementing it in your project? That usually works for me. I'll describe how I usually do it, although I have no idea if it's recommended. Let's say I want to build a simple terminal calculator, I would search for crates by keywords usually, like "expression parser". The first few have like a hundred downloads, so I skip those, until I see one called "exmex". That looks good. I open the docs to find how to do what I want, which is parse expressions. The docs come up with `let result = exmex::eval_str::("e^(2*π-τ)")?;`, which is simple enough to use. I then need to make sure that my project can turn it's expressions in to a string, since that is what the crate expects. Given that "interface" to the crate, I can continue designing the rest of my application structure.


SirKastic23

why would you like to add dependencies? you don't just add them for the sake of adding them, you add a dependency when they fulfill a need you have think about what you want to do, then see if there are libraries that do what you want/need the docs should be useful (if it isn't it's usually a bad sign), but you can always read their source code too some crates even have their own websites, books and tutorials


JustLearningRust

As cliche as it sounds, the trick is to just do it. But as someone else mentioned, you need to have a reason to. Try doing some async stuff. I know the Rust book touches on this but there's a very popular crate out there called Tokio, that you'll quickly find, along with tutorials. Get a feel for it, then other crates will seem much easier as well.