From 7310cac6f580a2aadb7fedc843b516201ca6fd71 Mon Sep 17 00:00:00 2001 From: gwenn Date: Tue, 31 Jul 2018 22:17:17 +0200 Subject: [PATCH] Use pub(crate) --- src/cache.rs | 1 - src/lib.rs | 2 -- src/row.rs | 34 +++++++--------------------------- src/statement.rs | 20 +++++--------------- 4 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/cache.rs b/src/cache.rs index cef1aca..82cd8ca 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -5,7 +5,6 @@ use std::ops::{Deref, DerefMut}; use lru_cache::LruCache; use {Result, Connection, Statement}; use raw_statement::RawStatement; -use statement::StatementCrateImpl; impl Connection { /// Prepare a SQL statement for execution, returning a previously prepared (but diff --git a/src/lib.rs b/src/lib.rs index 367258d..598520b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,10 +80,8 @@ use raw_statement::RawStatement; use cache::StatementCache; pub use statement::Statement; -use statement::StatementCrateImpl; pub use row::{Row, Rows, MappedRows, AndThenRows, RowIndex}; -use row::RowsCrateImpl; #[allow(deprecated)] pub use transaction::{SqliteTransaction, SqliteTransactionBehavior}; diff --git a/src/row.rs b/src/row.rs index 0e0c5d3..bbcee78 100644 --- a/src/row.rs +++ b/src/row.rs @@ -3,7 +3,6 @@ use std::marker::PhantomData; use super::{Statement, Error, Result}; use types::{FromSql, FromSqlError}; -use statement::StatementCrateImpl; /// An handle for the resulting rows of a query. pub struct Rows<'stmt> { @@ -49,19 +48,12 @@ impl<'stmt> Rows<'stmt> { } } -// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this -// once pub(crate) is stable. -pub trait RowsCrateImpl<'stmt> { - fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt>; - fn get_expected_row<'a>(&'a mut self) -> Result>; -} - -impl<'stmt> RowsCrateImpl<'stmt> for Rows<'stmt> { - fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt> { +impl<'stmt> Rows<'stmt> { + pub(crate) fn new(stmt: &'stmt Statement<'stmt>) -> Rows<'stmt> { Rows { stmt: Some(stmt) } } - fn get_expected_row<'a>(&'a mut self) -> Result> { + pub(crate) fn get_expected_row<'a>(&'a mut self) -> Result> { match self.next() { Some(row) => row, None => Err(Error::QueryReturnedNoRows), @@ -81,16 +73,10 @@ pub struct MappedRows<'stmt, F> { map: F, } -// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this -// once pub(crate) is stable. -pub trait MappedRowsCrateImpl<'stmt, T, F> { - fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F>; -} - -impl<'stmt, T, F> MappedRowsCrateImpl<'stmt, T, F> for MappedRows<'stmt, F> +impl<'stmt, T, F> MappedRows<'stmt, F> where F: FnMut(&Row) -> T { - fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> { + pub(crate) fn new(rows: Rows<'stmt>, f: F) -> MappedRows<'stmt, F> { MappedRows { rows, map: f } } } @@ -115,16 +101,10 @@ pub struct AndThenRows<'stmt, F> { map: F, } -// TODO: This trait lets us have "pub(crate)" visibility on some methods. Remove this -// once pub(crate) is stable. -pub trait AndThenRowsCrateImpl<'stmt, T, E, F> { - fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F>; -} - -impl<'stmt, T, E, F> AndThenRowsCrateImpl<'stmt, T, E, F> for AndThenRows<'stmt, F> +impl<'stmt, T, E, F> AndThenRows<'stmt, F> where F: FnMut(&Row) -> result::Result { - fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> { + pub(crate) fn new(rows: Rows<'stmt>, f: F) -> AndThenRows<'stmt, F> { AndThenRows { rows, map: f } } } diff --git a/src/statement.rs b/src/statement.rs index 2d44a57..5545617 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -7,7 +7,6 @@ use super::ffi; use super::{Connection, RawStatement, Result, Error, ValueRef, Row, Rows, AndThenRows, MappedRows}; use super::str_to_cstring; use types::{ToSql, ToSqlOutput}; -use row::{RowsCrateImpl, MappedRowsCrateImpl, AndThenRowsCrateImpl}; /// A prepared statement. pub struct Statement<'conn> { @@ -494,24 +493,15 @@ impl<'conn> Drop for Statement<'conn> { } } -// TODO: This trait lets us have "pub(crate)" visibility on some Statement methods. Remove this -// once pub(crate) is stable. -pub trait StatementCrateImpl<'conn> { - fn new(conn: &'conn Connection, stmt: RawStatement) -> Self; - fn value_ref(&self, col: usize) -> ValueRef; - fn step(&self) -> Result; - fn reset(&self) -> c_int; -} - -impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { - fn new(conn: &Connection, stmt: RawStatement) -> Statement { +impl<'conn> Statement<'conn> { + pub(crate) fn new(conn: &Connection, stmt: RawStatement) -> Statement { Statement { conn, stmt, } } - fn value_ref(&self, col: usize) -> ValueRef { + pub(crate) fn value_ref(&self, col: usize) -> ValueRef { let raw = unsafe { self.stmt.ptr() }; match self.stmt.column_type(col) { @@ -554,7 +544,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { } } - fn step(&self) -> Result { + pub(crate) fn step(&self) -> Result { match self.stmt.step() { ffi::SQLITE_ROW => Ok(true), ffi::SQLITE_DONE => Ok(false), @@ -562,7 +552,7 @@ impl<'conn> StatementCrateImpl<'conn> for Statement<'conn> { } } - fn reset(&self) -> c_int { + pub(crate) fn reset(&self) -> c_int { self.stmt.reset() } }