Improve the documentation of tokio-postgres connect#1099
Open
JJaviMS wants to merge 1 commit intorust-postgres:masterfrom
Open
Improve the documentation of tokio-postgres connect#1099JJaviMS wants to merge 1 commit intorust-postgres:masterfrom
JJaviMS wants to merge 1 commit intorust-postgres:masterfrom
Conversation
…cates the importance of the connection object
paolobarbolini
requested changes
Sep 21, 2025
Member
paolobarbolini
left a comment
There was a problem hiding this comment.
Good idea. I've left some minor changes
Comment on lines
+184
to
+187
| /// This method returns the client which will allow you to interact with the database and a connection | ||
| /// object which is the one that performs the communication with the dabase. **It's important to use the | ||
| /// connection object as shown in the below example, if it is ignored then the client object will not work | ||
| /// and when a .wait is called it will await forever.** |
Member
There was a problem hiding this comment.
I've cleaned it up a bit.
Suggested change
| /// This method returns the client which will allow you to interact with the database and a connection | |
| /// object which is the one that performs the communication with the dabase. **It's important to use the | |
| /// connection object as shown in the below example, if it is ignored then the client object will not work | |
| /// and when a .wait is called it will await forever.** | |
| /// This method returns the client object, which will allow you to interact with the database, | |
| /// and a connection object, which performs the communication with the database. | |
| /// | |
| /// **The connection object must be actively polled, which is usually done by spawning it into | |
| /// it's own tokio task, as shown below. If this is not done, calls to the client object will hang forever.** |
Comment on lines
192
to
193
| /// | ||
| /// [`Config`]: config/struct.Config.html |
Member
There was a problem hiding this comment.
This should go below the examples section.
Comment on lines
+195
to
+208
| /// # Examples | ||
| /// ``` | ||
| /// // Connect to the database. | ||
| /// let (client, connection) = | ||
| /// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?; | ||
| /// // The connection object performs the actual communication with the database, | ||
| /// // so spawn it off to run on its own. | ||
| /// tokio::spawn(async move { | ||
| /// if let Err(e) = connection.await { | ||
| /// eprintln!("connection error: {}", e); | ||
| /// } | ||
| /// }); | ||
| /// // Use the client | ||
| /// ``` |
Member
There was a problem hiding this comment.
Suggested change
| /// # Examples | |
| /// ``` | |
| /// // Connect to the database. | |
| /// let (client, connection) = | |
| /// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?; | |
| /// // The connection object performs the actual communication with the database, | |
| /// // so spawn it off to run on its own. | |
| /// tokio::spawn(async move { | |
| /// if let Err(e) = connection.await { | |
| /// eprintln!("connection error: {}", e); | |
| /// } | |
| /// }); | |
| /// // Use the client | |
| /// ``` | |
| /// # Examples | |
| /// | |
| /// ``` | |
| /// // Connect to the database. | |
| /// let (client, connection) = | |
| /// tokio_postgres::connect("host=localhost user=postgres", NoTls).await?; | |
| /// | |
| /// // The connection object performs the actual communication with the database, | |
| /// // so spawn it off to run on its own. | |
| /// tokio::spawn(async move { | |
| /// if let Err(e) = connection.await { | |
| /// eprintln!("connection error: {}", e); | |
| /// } | |
| /// }); | |
| /// | |
| /// // Now we can use the `client` | |
| /// ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As it can be seen on #924 and from my personal experience, it can be easily missed the use of the connection object when connecting using the tokio-postgres. I have improved the docs for that method so it indicates the importance of the connection object and give an example of how to use it.