How to read Crate documentation?

Hello

I have a huge problem understanding the standard documentation of Rust crates. They just give a list of all the structs they use and all the available functions. But that often doesn't really help me further.

Without an example, I personally find it impossible to implement something.

For example. I now want to use the function last_insert_id() from the MySQL-crate. I have found the function on this page.

Yet, I have no clue on how I'd use this function now. Instead of asking how to do x for every small thing, I'd like to learn how to read these documentations.

So, if someone could explain me on how to read this documentation and how to use the last_insert_id() function it'd be great!

Relevant piece of code:

let execute_result = conn.exec_drop(r"
            INSERT INTO users (
                username, email, birthdate, password
            ) VALUES (
                :username, :email, :birthdate, :password
            )", params! {
                "username" => &data.username,
                "email" => data.email,
                "birthdate" => date.format("%Y-%m-%d").to_string(),
                "password" => data.password
            });

PS.
Found on how to get the last_insert_id.

self.conn.get_conn().unwrap().last_insert_id();

Not due to the documentation though.

For crates that provide access to some upstream program or library, the documentation usually assumes that you're familiar with the corresponding function/method in the upstream library. In this case, the MySQL documentation has a lot to say about last_insert_id.

The crate documentation in this case only tells you how this has been translated into Rust's type system, but nothing about what it actually does.

2 Likes

Go to the git repository and read the readme for small examples. Check the examples folder in the repo for more examples. Large projects like Juniper, Actix have their own 'book' like documentation you can follow. These usually help you make a bare minimum starting template step by step.

The official docs are useful when you want some specific detail but pretty useless for getting started with things.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.