Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow FromSql to borrow from the buffer #342

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

Merged
merged 1 commit into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
build:
working_directory: ~/build
docker:
- image: rust:1.21.0
- image: rust:1.23.0
environment:
RUSTFLAGS: -D warnings
- image: sfackler/rust-postgres-test:3
Expand Down
2 changes: 0 additions & 2 deletions codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ extern crate marksman_escape;
extern crate phf_codegen;
extern crate regex;

#[allow(unused_imports)]
use std::ascii::AsciiExt;
use std::path::Path;

mod sqlstate;
Expand Down
17 changes: 5 additions & 12 deletions codegen/src/type_gen.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use marksman_escape::Escape;
use regex::Regex;
#[allow(unused_imports)]
use std::ascii::AsciiExt;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::Path;
use marksman_escape::Escape;

use snake_to_camel;

Expand Down Expand Up @@ -178,8 +176,7 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
w,
" {} => Some(Inner::{}),
",
oid,
type_.variant
oid, type_.variant
).unwrap();
}

Expand All @@ -194,14 +191,12 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
",
).unwrap();


for (oid, type_) in types {
write!(
w,
" Inner::{} => {},
",
type_.variant,
oid
type_.variant, oid
).unwrap();
}

Expand Down Expand Up @@ -231,8 +226,7 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
V
}}
",
type_.variant,
kind
type_.variant, kind
).unwrap();
}

Expand All @@ -252,8 +246,7 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
w,
r#" Inner::{} => "{}",
"#,
type_.variant,
type_.name
type_.variant, type_.name
).unwrap();
}

Expand Down
4 changes: 1 addition & 3 deletions postgres-shared/src/rows.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use fallible_iterator::FallibleIterator;
use postgres_protocol::message::backend::DataRowBody;
#[allow(unused_imports)]
use std::ascii::AsciiExt;
use std::io;
use std::ops::Range;

use stmt::Column;
use rows::sealed::Sealed;
use stmt::Column;

mod sealed {
use stmt::Column;
Expand Down
4 changes: 2 additions & 2 deletions postgres-shared/src/types/bit_vec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate bit_vec;

use postgres_protocol::types;
use self::bit_vec::BitVec;
use postgres_protocol::types;
use std::error::Error;

use types::{FromSql, IsNull, ToSql, Type, BIT, VARBIT};

impl FromSql for BitVec {
impl<'a> FromSql<'a> for BitVec {
fn from_sql(_: &Type, raw: &[u8]) -> Result<BitVec, Box<Error + Sync + Send>> {
let varbit = types::varbit_from_sql(raw)?;
let mut bitvec = BitVec::from_bytes(varbit.bytes());
Expand Down
14 changes: 7 additions & 7 deletions postgres-shared/src/types/chrono.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extern crate chrono;

use postgres_protocol::types;
use self::chrono::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime,
Utc};
use postgres_protocol::types;
use std::error::Error;

use types::{FromSql, IsNull, ToSql, Type, DATE, TIME, TIMESTAMP, TIMESTAMPTZ};
Expand All @@ -11,7 +11,7 @@ fn base() -> NaiveDateTime {
NaiveDate::from_ymd(2000, 1, 1).and_hms(0, 0, 0)
}

impl FromSql for NaiveDateTime {
impl<'a> FromSql<'a> for NaiveDateTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDateTime, Box<Error + Sync + Send>> {
let t = types::timestamp_from_sql(raw)?;
Ok(base() + Duration::microseconds(t))
Expand All @@ -34,7 +34,7 @@ impl ToSql for NaiveDateTime {
to_sql_checked!();
}

impl FromSql for DateTime<Utc> {
impl<'a> FromSql<'a> for DateTime<Utc> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Utc>, Box<Error + Sync + Send>> {
let naive = NaiveDateTime::from_sql(type_, raw)?;
Ok(DateTime::from_utc(naive, Utc))
Expand All @@ -52,7 +52,7 @@ impl ToSql for DateTime<Utc> {
to_sql_checked!();
}

impl FromSql for DateTime<Local> {
impl<'a> FromSql<'a> for DateTime<Local> {
fn from_sql(type_: &Type, raw: &[u8]) -> Result<DateTime<Local>, Box<Error + Sync + Send>> {
let utc = DateTime::<Utc>::from_sql(type_, raw)?;
Ok(utc.with_timezone(&Local))
Expand All @@ -70,7 +70,7 @@ impl ToSql for DateTime<Local> {
to_sql_checked!();
}

impl FromSql for DateTime<FixedOffset> {
impl<'a> FromSql<'a> for DateTime<FixedOffset> {
fn from_sql(
type_: &Type,
raw: &[u8],
Expand All @@ -91,7 +91,7 @@ impl ToSql for DateTime<FixedOffset> {
to_sql_checked!();
}

impl FromSql for NaiveDate {
impl<'a> FromSql<'a> for NaiveDate {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveDate, Box<Error + Sync + Send>> {
let jd = types::date_from_sql(raw)?;
Ok(base().date() + Duration::days(jd as i64))
Expand All @@ -115,7 +115,7 @@ impl ToSql for NaiveDate {
to_sql_checked!();
}

impl FromSql for NaiveTime {
impl<'a> FromSql<'a> for NaiveTime {
fn from_sql(_: &Type, raw: &[u8]) -> Result<NaiveTime, Box<Error + Sync + Send>> {
let usec = types::time_from_sql(raw)?;
Ok(NaiveTime::from_hms(0, 0, 0) + Duration::microseconds(usec))
Expand Down
6 changes: 3 additions & 3 deletions postgres-shared/src/types/eui48.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate eui48;

use self::eui48::MacAddress;
use std::error::Error;
use postgres_protocol::types;
use std::error::Error;

use types::{FromSql, ToSql, Type, IsNull, MACADDR};
use types::{FromSql, IsNull, ToSql, Type, MACADDR};

impl FromSql for MacAddress {
impl<'a> FromSql<'a> for MacAddress {
fn from_sql(_: &Type, raw: &[u8]) -> Result<MacAddress, Box<Error + Sync + Send>> {
let bytes = types::macaddr_from_sql(raw)?;
Ok(MacAddress::new(bytes))
Expand Down
12 changes: 6 additions & 6 deletions postgres-shared/src/types/geo.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate geo;

use postgres_protocol::types;
use self::geo::{Bbox, LineString, Point};
use std::error::Error;
use fallible_iterator::FallibleIterator;
use postgres_protocol::types;
use std::error::Error;

use types::{FromSql, ToSql, IsNull, Type, POINT, BOX, PATH};
use types::{FromSql, IsNull, ToSql, Type, BOX, PATH, POINT};

impl FromSql for Point<f64> {
impl<'a> FromSql<'a> for Point<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
let point = types::point_from_sql(raw)?;
Ok(Point::new(point.x(), point.y()))
Expand All @@ -26,7 +26,7 @@ impl ToSql for Point<f64> {
to_sql_checked!();
}

impl FromSql for Bbox<f64> {
impl<'a> FromSql<'a> for Bbox<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
let bbox = types::box_from_sql(raw)?;
Ok(Bbox {
Expand All @@ -50,7 +50,7 @@ impl ToSql for Bbox<f64> {
to_sql_checked!();
}

impl FromSql for LineString<f64> {
impl<'a> FromSql<'a> for LineString<f64> {
fn from_sql(_: &Type, raw: &[u8]) -> Result<Self, Box<Error + Sync + Send>> {
let path = types::path_from_sql(raw)?;
let points = path.points().map(|p| Point::new(p.x(), p.y())).collect()?;
Expand Down
Loading