diff --git a/src/base.rs b/src/base.rs index 954ec3b0..fbfccfbd 100644 --- a/src/base.rs +++ b/src/base.rs @@ -33,7 +33,7 @@ pub trait Type { /// Returns a `GlobalID` that is unique among all types. fn global_id(id: ID) -> ID { - base64::encode(format!("{}:{}", Self::type_name(), id)).into() + base64::encode(format!("{}:{}", Self::type_name(), *id)).into() } /// Parse `GlobalID`. diff --git a/src/lib.rs b/src/lib.rs index b2c8da29..9be5d353 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -122,7 +122,7 @@ pub use error::{ pub use parser::{Pos, Positioned, Value}; pub use query::{IntoQueryBuilder, IntoQueryBuilderOpts, QueryBuilder, QueryResponse}; pub use registry::CacheControl; -pub use scalars::{Any, Json, ToGraphQLID, ID}; +pub use scalars::{Any, Json, ID}; pub use schema::Schema; pub use subscription::{ SimpleBroker, SubscriptionStream, SubscriptionStreams, SubscriptionTransport, @@ -130,7 +130,7 @@ pub use subscription::{ }; pub use types::{ Connection, Cursor, DataSource, EmptyEdgeFields, EmptyMutation, EmptySubscription, PageInfo, - QueryOperation, ToGraphQLCursor, Upload, + QueryOperation, Upload, }; pub use validation::ValidationMode; diff --git a/src/scalars/id.rs b/src/scalars/id.rs index ee10f93b..19a5e82d 100644 --- a/src/scalars/id.rs +++ b/src/scalars/id.rs @@ -12,12 +12,6 @@ use uuid::Uuid; #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] pub struct ID(String); -impl std::fmt::Display for ID { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - impl Deref for ID { type Target = String; @@ -32,9 +26,12 @@ impl DerefMut for ID { } } -impl From for ID { - fn from(value: String) -> Self { - ID(value) +impl From for ID +where + T: std::fmt::Display, +{ + fn from(value: T) -> Self { + ID(value.to_string()) } } @@ -44,18 +41,6 @@ impl Into for ID { } } -impl<'a> From<&'a str> for ID { - fn from(value: &'a str) -> Self { - ID(value.to_string()) - } -} - -impl From for ID { - fn from(value: usize) -> Self { - ID(value.to_string()) - } -} - impl TryInto for ID { type Error = ParseIntError; @@ -64,12 +49,6 @@ impl TryInto for ID { } } -impl From for ID { - fn from(uuid: Uuid) -> ID { - ID(uuid.to_string()) - } -} - impl TryInto for ID { type Error = uuid::Error; @@ -78,12 +57,6 @@ impl TryInto for ID { } } -impl From for ID { - fn from(object_id: ObjectId) -> ID { - ID(object_id.to_hex()) - } -} - impl TryInto for ID { type Error = oid::Error; @@ -98,21 +71,6 @@ impl PartialEq<&str> for ID { } } -/// Convert any type that implements Display to the ID type -pub trait ToGraphQLID { - #[allow(missing_docs)] - fn to_graphql_id(&self) -> ID; -} - -impl ToGraphQLID for T -where - T: std::fmt::Display, -{ - fn to_graphql_id(&self) -> ID { - ID(self.to_string()) - } -} - #[Scalar(internal)] impl ScalarType for ID { fn type_name() -> &'static str { diff --git a/src/scalars/mod.rs b/src/scalars/mod.rs index 37be2ddb..755c2397 100644 --- a/src/scalars/mod.rs +++ b/src/scalars/mod.rs @@ -15,7 +15,7 @@ mod bson; mod uuid; pub use any::Any; -pub use id::{ToGraphQLID, ID}; +pub use id::ID; pub use json::Json; #[cfg(test)] diff --git a/src/types/connection/cursor.rs b/src/types/connection/cursor.rs index 1022dda1..9c4d6ce4 100644 --- a/src/types/connection/cursor.rs +++ b/src/types/connection/cursor.rs @@ -9,12 +9,6 @@ use std::ops::{Deref, DerefMut}; #[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] pub struct Cursor(String); -impl std::fmt::Display for Cursor { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - impl Deref for Cursor { type Target = String; @@ -29,36 +23,12 @@ impl DerefMut for Cursor { } } -impl From for Cursor { - fn from(value: String) -> Self { - Cursor(value) - } -} - -impl<'a> From<&'a str> for Cursor { - fn from(value: &'a str) -> Self { - Cursor(value.to_string()) - } -} - -impl From for Cursor { - fn from(value: usize) -> Self { - Cursor(value.to_string()) - } -} - -/// Convert any type that implements Display to the Cursor type -pub trait ToGraphQLCursor { - #[allow(missing_docs)] - fn to_graphql_cursor(&self) -> Cursor; -} - -impl ToGraphQLCursor for T +impl From for Cursor where T: std::fmt::Display, { - fn to_graphql_cursor(&self) -> Cursor { - Cursor(self.to_string()) + fn from(value: T) -> Self { + Cursor(value.to_string()) } } diff --git a/src/types/connection/mod.rs b/src/types/connection/mod.rs index 15f3b532..75613240 100644 --- a/src/types/connection/mod.rs +++ b/src/types/connection/mod.rs @@ -7,7 +7,7 @@ mod slice; use crate::{Context, FieldResult, ObjectType}; pub use connection_type::Connection; -pub use cursor::{Cursor, ToGraphQLCursor}; +pub use cursor::Cursor; pub use page_info::PageInfo; /// Connection query operation diff --git a/src/types/mod.rs b/src/types/mod.rs index f0521357..4d740656 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -7,9 +7,7 @@ mod optional; mod query_root; mod upload; -pub use connection::{ - Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation, ToGraphQLCursor, -}; +pub use connection::{Connection, Cursor, DataSource, EmptyEdgeFields, PageInfo, QueryOperation}; pub use empty_mutation::EmptyMutation; pub use empty_subscription::EmptySubscription; pub use query_root::QueryRoot;