Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the documentation of tokio-postgres connect #1099

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions tokio-postgres/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,32 @@ mod transaction_builder;
pub mod types;

/// A convenience function which parses a connection string and connects to the database.
///
/// 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.**
///
/// See the documentation for [`Config`] for details on the connection string format.
///
/// Requires the `runtime` Cargo feature (enabled by default).
///
/// [`Config`]: config/struct.Config.html
///
/// # 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
/// ```
#[cfg(feature = "runtime")]
pub async fn connect<T>(
config: &str,
Expand Down