Skip to content

Commit 42dcfb5

Browse files
committed
seal BorrowToSql
1 parent 0e494a0 commit 42dcfb5

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

postgres-types/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#![doc(html_root_url = "https://docs.rs/postgres-types/0.1")]
109109
#![warn(clippy::all, rust_2018_idioms, missing_docs)]
110110

111+
use crate::sealed::Sealed;
111112
use fallible_iterator::FallibleIterator;
112113
use postgres_protocol::types::{self, ArrayDimension};
113114
use std::any::type_name;
@@ -952,18 +953,29 @@ fn downcast(len: usize) -> Result<i32, Box<dyn Error + Sync + Send>> {
952953
}
953954
}
954955

955-
/// A helper trait to be able create a parameters iterator from `&dyn ToSql` or `T: ToSql`
956-
pub trait BorrowToSql {
956+
mod sealed {
957+
pub trait Sealed {}
958+
}
959+
960+
/// A helper trait used internally by Rust-Postgres
961+
/// to be able create a parameters iterator from `&dyn ToSql` or `T: ToSql`.
962+
///
963+
/// /// This cannot be implemented outside of this crate.
964+
pub trait BorrowToSql: sealed::Sealed {
957965
/// Get a reference to a `ToSql` trait object
958966
fn borrow_to_sql(&self) -> &dyn ToSql;
959967
}
960968

969+
impl Sealed for &dyn ToSql {}
970+
961971
impl BorrowToSql for &dyn ToSql {
962972
fn borrow_to_sql(&self) -> &dyn ToSql {
963973
*self
964974
}
965975
}
966976

977+
impl<T: ToSql> Sealed for T {}
978+
967979
impl<T: ToSql> BorrowToSql for T {
968980
fn borrow_to_sql(&self) -> &dyn ToSql {
969981
self

0 commit comments

Comments
 (0)