diff --git a/src/scalars/id.rs b/src/scalars/id.rs index 19a5e82d..f1fa8bd8 100644 --- a/src/scalars/id.rs +++ b/src/scalars/id.rs @@ -1,7 +1,7 @@ use crate::{InputValueError, InputValueResult, Result, ScalarType, Value}; use async_graphql_derive::Scalar; use bson::oid::{self, ObjectId}; -use std::convert::TryInto; +use std::convert::TryFrom; use std::num::ParseIntError; use std::ops::{Deref, DerefMut}; use uuid::Uuid; @@ -41,27 +41,27 @@ impl Into for ID { } } -impl TryInto for ID { +impl TryFrom for usize { type Error = ParseIntError; - fn try_into(self) -> std::result::Result { - self.0.parse() + fn try_from(id: ID) -> std::result::Result { + id.0.parse() } } -impl TryInto for ID { +impl TryFrom for Uuid { type Error = uuid::Error; - fn try_into(self) -> std::result::Result { - Uuid::parse_str(&self.0) + fn try_from(id: ID) -> std::result::Result { + Uuid::parse_str(&id.0) } } -impl TryInto for ID { +impl TryFrom for ObjectId { type Error = oid::Error; - fn try_into(self) -> std::result::Result { - ObjectId::with_string(&self.0) + fn try_from(id: ID) -> std::result::Result { + ObjectId::with_string(&id.0) } } diff --git a/src/types/connection/cursor.rs b/src/types/connection/cursor.rs index 9c4d6ce4..27d40588 100644 --- a/src/types/connection/cursor.rs +++ b/src/types/connection/cursor.rs @@ -1,4 +1,4 @@ -use crate::{InputValueError, InputValueResult, Result, ScalarType, Value}; +use crate::{InputValueError, InputValueResult, Result, ScalarType, Value, ID}; use async_graphql_derive::Scalar; use std::ops::{Deref, DerefMut}; @@ -32,6 +32,12 @@ where } } +impl From for Cursor { + fn from(id: ID) -> Self { + Cursor(id.into()) + } +} + #[Scalar(internal)] impl ScalarType for Cursor { fn type_name() -> &'static str {