From 08d2c79279f93a504a35aaed3c159209483771b2 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Fri, 24 Jul 2020 07:28:59 -0700 Subject: [PATCH] feat(postgres): expose PgTypeKind --- sqlx-core/src/postgres/mod.rs | 2 +- sqlx-core/src/postgres/type_info.rs | 5 ++--- tests/postgres/describe.rs | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sqlx-core/src/postgres/mod.rs b/sqlx-core/src/postgres/mod.rs index 0f095514..ff20b28d 100644 --- a/sqlx-core/src/postgres/mod.rs +++ b/sqlx-core/src/postgres/mod.rs @@ -32,7 +32,7 @@ pub use options::{PgConnectOptions, PgSslMode}; pub use row::PgRow; pub use statement::PgStatement; pub use transaction::PgTransactionManager; -pub use type_info::PgTypeInfo; +pub use type_info::{PgTypeInfo, PgTypeKind}; pub use value::{PgValue, PgValueFormat, PgValueRef}; /// An alias for [`Pool`][crate::pool::Pool], specialized for Postgres. diff --git a/sqlx-core/src/postgres/type_info.rs b/sqlx-core/src/postgres/type_info.rs index 1791f2f9..4449a804 100644 --- a/sqlx-core/src/postgres/type_info.rs +++ b/sqlx-core/src/postgres/type_info.rs @@ -141,7 +141,6 @@ pub struct PgCustomType { #[derive(Debug, Clone)] #[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))] -#[doc(hidden)] pub enum PgTypeKind { Simple, Pseudo, @@ -158,8 +157,8 @@ impl PgTypeInfo { PgType::try_from_oid(oid).map(Self) } - #[doc(hidden)] - pub fn __kind(&self) -> &PgTypeKind { + /// Returns the _kind_ (simple, array, enum, etc.) for this type. + pub fn kind(&self) -> &PgTypeKind { self.0.kind() } diff --git a/tests/postgres/describe.rs b/tests/postgres/describe.rs index d392e0b5..d128eb21 100644 --- a/tests/postgres/describe.rs +++ b/tests/postgres/describe.rs @@ -55,7 +55,7 @@ async fn it_describes_enum() -> anyhow::Result<()> { assert_eq!(ty.name(), "status"); assert_eq!( - format!("{:?}", ty.__kind()), + format!("{:?}", ty.kind()), r#"Enum(["new", "open", "closed"])"# ); @@ -87,7 +87,7 @@ async fn it_describes_composite() -> anyhow::Result<()> { assert_eq!(ty.name(), "inventory_item"); assert_eq!( - format!("{:?}", ty.__kind()), + format!("{:?}", ty.kind()), r#"Composite([("name", PgTypeInfo(Text)), ("supplier_id", PgTypeInfo(Int4)), ("price", PgTypeInfo(Int8))])"# );