@@ -267,6 +267,24 @@ pub struct PostgresCancelData {
267267/// A `PostgresCancelData` object can be created via
268268/// `PostgresConnection::cancel_data`. The object can cancel any query made on
269269/// that connection.
270+ ///
271+ /// # Example
272+ ///
273+ /// ```rust
274+ /// # extern crate postgres;
275+ /// # fn main() {}
276+ /// # fn foo() {
277+ /// # use postgres::{PostgresConnection, NoSsl};
278+ /// # let url = "";
279+ /// let conn = PostgresConnection::connect(url, &NoSsl);
280+ /// let cancel_data = conn.cancel_data();
281+ /// spawn(proc() {
282+ /// conn.execute("SOME EXPENSIVE QUERY", []);
283+ /// });
284+ /// # let _ =
285+ /// postgres::cancel_query(url, &NoSsl, cancel_data);
286+ /// # }
287+ /// ```
270288pub fn cancel_query ( url : & str , ssl : & SslMode , data : PostgresCancelData )
271289 -> Result < ( ) , PostgresConnectError > {
272290 let Url { host, port, .. } : Url = match FromStr :: from_str ( url) {
@@ -691,6 +709,21 @@ impl PostgresConnection {
691709 /// The password may be omitted if not required. The default Postgres port
692710 /// (5432) is used if none is specified. The database name defaults to the
693711 /// username if not specified.
712+ ///
713+ /// # Example
714+ ///
715+ /// ```rust
716+ /// # fn main() {}
717+ /// # fn foo() {
718+ /// # use postgres::{PostgresConnection, NoSsl};
719+ /// let url = "postgres://postgres:hunter2@localhost:2994/foodb";
720+ /// let maybe_conn = PostgresConnection::try_connect(url, &NoSsl);
721+ /// let conn = match maybe_conn {
722+ /// Ok(conn) => conn,
723+ /// Err(err) => fail!("Error connecting: {}", err)
724+ /// };
725+ /// # }
726+ /// ```
694727 pub fn try_connect ( url : & str , ssl : & SslMode )
695728 -> Result < PostgresConnection , PostgresConnectError > {
696729 InnerPostgresConnection :: try_connect ( url, ssl) . map ( |conn| {
@@ -736,6 +769,20 @@ impl PostgresConnection {
736769 ///
737770 /// The statement is associated with the connection that created it and may
738771 /// not outlive that connection.
772+ ///
773+ /// # Example
774+ ///
775+ /// ```rust
776+ /// # use postgres::{PostgresConnection, NoSsl};
777+ /// # fn main() {}
778+ /// # fn foo() {
779+ /// # let conn = PostgresConnection::connect("", &NoSsl);
780+ /// let maybe_stmt = conn.try_prepare("SELECT foo FROM bar WHERE baz = $1");
781+ /// let stmt = match maybe_stmt {
782+ /// Ok(stmt) => stmt,
783+ /// Err(err) => fail!("Error preparing statement: {}", err)
784+ /// };
785+ /// # }
739786 pub fn try_prepare < ' a > ( & ' a self , query : & str )
740787 -> Result < NormalPostgresStatement < ' a > , PostgresError > {
741788 self . conn . with_mut ( |conn| conn. try_prepare ( query, self ) )
@@ -761,6 +808,26 @@ impl PostgresConnection {
761808 /// is active until the `PostgresTransaction` object falls out of scope.
762809 /// A transaction will commit by default unless the task fails or the
763810 /// transaction is set to roll back.
811+ ///
812+ /// # Example
813+ ///
814+ /// ```rust
815+ /// # use postgres::{PostgresConnection, NoSsl};
816+ /// # fn main() {}
817+ /// # fn foo() -> Result<(), postgres::error::PostgresError> {
818+ /// # let conn = PostgresConnection::connect("", &NoSsl);
819+ /// let trans = try!(conn.try_transaction());
820+ /// trans.execute("UPDATE foo SET bar = 10", []);
821+ ///
822+ /// # let something_bad_happened = true;
823+ /// if something_bad_happened {
824+ /// trans.set_rollback();
825+ /// }
826+ ///
827+ /// drop(trans);
828+ /// # Ok(())
829+ /// # }
830+ /// ```
764831 pub fn try_transaction < ' a > ( & ' a self )
765832 -> Result < PostgresTransaction < ' a > , PostgresError > {
766833 check_desync ! ( self ) ;
0 commit comments