Skip to content

Commit 97efc52

Browse files
committed
Formatting cleanup
1 parent 455dea3 commit 97efc52

2 files changed

Lines changed: 28 additions & 57 deletions

File tree

README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
Rust-Postgres
2-
=============
1+
# Rust-Postgres
32
A native PostgreSQL driver for Rust.
43

54
Documentation is available at http://www.rust-ci.org/sfackler/rust-postgres/doc/postgres/.
65

76
[![Build Status](https://travis-ci.org/sfackler/rust-postgres.png?branch=master)](https://travis-ci.org/sfackler/rust-postgres)
87

9-
Overview
10-
========
8+
## Overview
119
Rust-Postgres is a pure-Rust frontend for the popular PostgreSQL database. It
1210
exposes a high level interface in the vein of JDBC or Go's `database/sql`
1311
package.
@@ -61,9 +59,7 @@ fn main() {
6159
}
6260
```
6361

64-
Requirements
65-
============
66-
62+
## Requirements
6763
* **Rust** - Rust-Postgres is developed against the *master* branch of the Rust
6864
repository. It will most likely not build against the versioned releases on
6965
http://www.rust-lang.org.
@@ -72,11 +68,9 @@ Requirements
7268
PostgreSQL protocol, which corresponds to versions 7.4 and later. If your
7369
version of Postgres was compiled in the last decade, you should be okay.
7470

75-
Usage
76-
=====
71+
## Usage
7772

78-
Connecting
79-
----------
73+
### Connecting
8074
Connect to a Postgres server using the standard URI format:
8175
```rust
8276
let conn = try!(PostgresConnection::connect("postgres://user:pass@host:port/database?arg1=val1&arg2=val2",
@@ -95,16 +89,14 @@ let conn = try!(PosgresConnection::connect("postgres://postgres@%2Frun%2Fpostgre
9589
Paths which contain non-UTF8 characters can be handled in a different manner;
9690
see the documentation for details.
9791

98-
Statement Preparation
99-
---------------------
92+
### Statement Preparation
10093
Prepared statements can have parameters, represented as `$n` where `n` is an
10194
index into the parameter array starting from 1:
10295
```rust
10396
let stmt = try!(conn.prepare("SELECT * FROM foo WHERE bar = $1 AND baz = $2"));
10497
```
10598

106-
Querying
107-
--------
99+
### Querying
108100
A prepared statement can be executed with the `query` and `execute` methods.
109101
Both methods take an array of parameters to bind to the query represented as
110102
`&ToSql` trait objects. `execute` returns the number of rows affected by the
@@ -134,8 +126,7 @@ let updates = try!(conn.execute("UPDATE foo SET bar = $1 WHERE baz = $2",
134126
println!("{} rows were updated", updates);
135127
```
136128

137-
Transactions
138-
------------
129+
### Transactions
139130
The `transaction` method will start a new transaction. It returns a
140131
`PostgresTransaction` object which has the functionality of a
141132
`PostgresConnection` as well as methods to control the result of the
@@ -155,8 +146,7 @@ The transaction will be active until the `PostgresTransaction` object falls out
155146
of scope. A transaction will roll back by default. Nested transactions are
156147
supported via savepoints.
157148

158-
Connection Pooling
159-
------------------
149+
### Connection Pooling
160150
A very basic fixed-size connection pool is provided in the `pool` module. A
161151
single pool can be shared across tasks and `get_connection` will block until a
162152
connection is available.
@@ -173,8 +163,7 @@ for _ in range(0, 10) {
173163
}
174164
```
175165

176-
Type Correspondence
177-
-------------------
166+
### Type Correspondence
178167
Rust-Postgres enforces a strict correspondence between Rust types and Postgres
179168
types. The driver currently supports the following conversions:
180169

@@ -308,8 +297,7 @@ types. The driver currently supports the following conversions:
308297
More conversions can be defined by implementing the `ToSql` and `FromSql`
309298
traits.
310299

311-
Development
312-
===========
300+
## Development
313301
Like Rust itself, Rust-Postgres is still in the early stages of development, so
314302
don't be surprised if APIs change and things break. If something's not working
315303
properly, file an issue or submit a pull request!

src/types/mod.rs

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ pub trait FromSql {
220220
/// Creates a new value of this type from a buffer of Postgres data.
221221
///
222222
/// If the value was `NULL`, the buffer will be `None`.
223-
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
224-
-> PostgresResult<Self>;
223+
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>) -> PostgresResult<Self>;
225224
}
226225

227226
#[doc(hidden)]
@@ -282,8 +281,7 @@ impl RawFromSql for Timespec {
282281
macro_rules! from_range_impl(
283282
($t:ty) => (
284283
impl RawFromSql for Range<$t> {
285-
fn raw_from_sql<R: Reader>(rdr: &mut R)
286-
-> PostgresResult<Range<$t>> {
284+
fn raw_from_sql<R: Reader>(rdr: &mut R) -> PostgresResult<Range<$t>> {
287285
let t = try_pg!(rdr.read_i8());
288286

289287
if t & RANGE_EMPTY != 0 {
@@ -444,8 +442,7 @@ impl FromSql for Option<HashMap<String, Option<String>>> {
444442
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
445443
-> PostgresResult<Option<HashMap<String, Option<String>>>> {
446444
match *ty {
447-
PgUnknownType { name: ref name, .. }
448-
if "hstore" == name.as_slice() => {}
445+
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
449446
_ => return Err(PgWrongType(ty.clone()))
450447
}
451448

@@ -548,31 +545,27 @@ raw_to_impl!(f64, write_be_f64)
548545

549546
impl RawToSql for Timespec {
550547
fn raw_to_sql<W: Writer>(&self, w: &mut W) -> PostgresResult<()> {
551-
let t = (self.sec - TIME_SEC_CONVERSION) * USEC_PER_SEC
552-
+ self.nsec as i64 / NSEC_PER_USEC;
548+
let t = (self.sec - TIME_SEC_CONVERSION) * USEC_PER_SEC + self.nsec as i64 / NSEC_PER_USEC;
553549
Ok(try_pg!(w.write_be_i64(t)))
554550
}
555551
}
556552

557553
macro_rules! to_range_impl(
558554
($t:ty) => (
559555
impl RawToSql for Range<$t> {
560-
fn raw_to_sql<W: Writer>(&self, buf: &mut W)
561-
-> PostgresResult<()> {
556+
fn raw_to_sql<W: Writer>(&self, buf: &mut W) -> PostgresResult<()> {
562557
let mut tag = 0;
563558
if self.is_empty() {
564559
tag |= RANGE_EMPTY;
565560
} else {
566561
match self.lower() {
567562
None => tag |= RANGE_LOWER_UNBOUNDED,
568-
Some(&RangeBound { type_: Inclusive, .. }) =>
569-
tag |= RANGE_LOWER_INCLUSIVE,
563+
Some(&RangeBound { type_: Inclusive, .. }) => tag |= RANGE_LOWER_INCLUSIVE,
570564
_ => {}
571565
}
572566
match self.upper() {
573567
None => tag |= RANGE_UPPER_UNBOUNDED,
574-
Some(&RangeBound { type_: Inclusive, .. }) =>
575-
tag |= RANGE_UPPER_INCLUSIVE,
568+
Some(&RangeBound { type_: Inclusive, .. }) => tag |= RANGE_UPPER_INCLUSIVE,
576569
_ => {}
577570
}
578571
}
@@ -619,8 +612,7 @@ impl RawToSql for Json {
619612
macro_rules! to_option_impl(
620613
($($oid:pat)|+, $t:ty) => (
621614
impl ToSql for Option<$t> {
622-
fn to_sql(&self, ty: &PostgresType)
623-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
615+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
624616
check_types!($($oid)|+, ty)
625617

626618
match *self {
@@ -635,8 +627,7 @@ macro_rules! to_option_impl(
635627
macro_rules! to_option_impl_lifetime(
636628
($($oid:pat)|+, $t:ty) => (
637629
impl<'a> ToSql for Option<$t> {
638-
fn to_sql(&self, ty: &PostgresType)
639-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
630+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
640631
check_types!($($oid)|+, ty)
641632

642633
match *self {
@@ -651,8 +642,7 @@ macro_rules! to_option_impl_lifetime(
651642
macro_rules! to_raw_to_impl(
652643
($($oid:ident)|+, $t:ty) => (
653644
impl ToSql for $t {
654-
fn to_sql(&self, ty: &PostgresType)
655-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
645+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
656646
check_types!($($oid)|+, ty)
657647

658648
let mut writer = MemWriter::new();
@@ -680,8 +670,7 @@ to_raw_to_impl!(PgInt8Range, Range<i64>)
680670
to_raw_to_impl!(PgTsRange | PgTstzRange, Range<Timespec>)
681671

682672
impl<'a> ToSql for &'a str {
683-
fn to_sql(&self, ty: &PostgresType)
684-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
673+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
685674
check_types!(PgVarchar | PgText | PgCharN | PgName, ty)
686675
Ok((Text, Some(Vec::from_slice(self.as_bytes()))))
687676
}
@@ -690,8 +679,7 @@ impl<'a> ToSql for &'a str {
690679
to_option_impl_lifetime!(PgVarchar | PgText | PgCharN | PgName, &'a str)
691680

692681
impl<'a> ToSql for &'a [u8] {
693-
fn to_sql(&self, ty: &PostgresType)
694-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
682+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
695683
check_types!(PgByteA, ty)
696684
Ok((Binary, Some(Vec::from_slice(*self))))
697685
}
@@ -704,8 +692,7 @@ to_raw_to_impl!(PgTimestamp | PgTimestampTZ, Timespec)
704692
macro_rules! to_array_impl(
705693
($($oid:ident)|+, $t:ty) => (
706694
impl ToSql for ArrayBase<Option<$t>> {
707-
fn to_sql(&self, ty: &PostgresType)
708-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
695+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
709696
check_types!($($oid)|+, ty)
710697
let mut buf = MemWriter::new();
711698

@@ -755,11 +742,9 @@ to_array_impl!(PgInt8RangeArray, Range<i64>)
755742
to_array_impl!(PgJsonArray, Json)
756743

757744
impl ToSql for HashMap<String, Option<String>> {
758-
fn to_sql(&self, ty: &PostgresType)
759-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
745+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
760746
match *ty {
761-
PgUnknownType { name: ref name, .. }
762-
if "hstore" == name.as_slice() => {}
747+
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
763748
_ => return Err(PgWrongType(ty.clone()))
764749
}
765750

@@ -785,11 +770,9 @@ impl ToSql for HashMap<String, Option<String>> {
785770
}
786771

787772
impl ToSql for Option<HashMap<String, Option<String>>> {
788-
fn to_sql(&self, ty: &PostgresType)
789-
-> PostgresResult<(Format, Option<Vec<u8>>)> {
773+
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {
790774
match *ty {
791-
PgUnknownType { name: ref name, .. }
792-
if "hstore" == name.as_slice() => {}
775+
PgUnknownType { name: ref name, .. } if "hstore" == name.as_slice() => {}
793776
_ => return Err(PgWrongType(ty.clone()))
794777
}
795778

0 commit comments

Comments
 (0)