From 0344b0b996c30c14ecfa7ae0f01109781a49d469 Mon Sep 17 00:00:00 2001 From: Samuel Hurel Date: Sun, 10 May 2020 16:13:41 +0200 Subject: [PATCH] Prefer TryFrom to TryInto for ID --- src/scalars/id.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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) } }