From 3b3b0964aa049fe030db864d83886e07a9e676c9 Mon Sep 17 00:00:00 2001 From: aumetra Date: Fri, 27 Oct 2023 22:14:07 +0200 Subject: [PATCH] Move `speedy-uuid` impl block (#390) --- lib/speedy-uuid/src/lib.rs | 86 +++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/speedy-uuid/src/lib.rs b/lib/speedy-uuid/src/lib.rs index 16d4bf7a8..ec78a05f8 100644 --- a/lib/speedy-uuid/src/lib.rs +++ b/lib/speedy-uuid/src/lib.rs @@ -112,6 +112,49 @@ impl FromStr for Uuid { } } +#[cfg(feature = "async-graphql")] +mod async_graphql_impl { + use super::Uuid; + use async_graphql::{ + connection::CursorType, InputValueError, InputValueResult, Scalar, ScalarType, Value, + }; + use std::str::FromStr; + + impl CursorType for Uuid { + type Error = crate::Error; + + fn decode_cursor(s: &str) -> Result { + s.parse() + } + + fn encode_cursor(&self) -> String { + self.to_string() + } + } + + /// A UUID is a unique 128-bit number, stored as 16 octets. UUIDs are parsed as + /// Strings within GraphQL. UUIDs are used to assign unique identifiers to + /// entities without requiring a central allocating authority. + /// + /// # References + /// + /// * [Wikipedia: Universally Unique Identifier](http://en.wikipedia.org/wiki/Universally_unique_identifier) + /// * [RFC4122: A Universally Unique IDentifier (UUID) URN Namespace](http://tools.ietf.org/html/rfc4122) + #[Scalar(name = "UUID", specified_by_url = "http://tools.ietf.org/html/rfc4122")] + impl ScalarType for Uuid { + fn parse(value: Value) -> InputValueResult { + match value { + Value::String(s) => Ok(Uuid::from_str(&s)?), + _ => Err(InputValueError::expected_type(value)), + } + } + + fn to_value(&self) -> Value { + Value::String(self.to_string()) + } + } +} + #[cfg(feature = "diesel")] mod diesel_impl { use crate::Uuid; @@ -261,46 +304,3 @@ mod test { assert_eq!(UUID_1, uuid.to_string()); } } - -#[cfg(feature = "async-graphql")] -mod async_graphql_impl { - use super::Uuid; - use async_graphql::{ - connection::CursorType, InputValueError, InputValueResult, Scalar, ScalarType, Value, - }; - use std::str::FromStr; - - impl CursorType for Uuid { - type Error = crate::Error; - - fn decode_cursor(s: &str) -> Result { - s.parse() - } - - fn encode_cursor(&self) -> String { - self.to_string() - } - } - - /// A UUID is a unique 128-bit number, stored as 16 octets. UUIDs are parsed as - /// Strings within GraphQL. UUIDs are used to assign unique identifiers to - /// entities without requiring a central allocating authority. - /// - /// # References - /// - /// * [Wikipedia: Universally Unique Identifier](http://en.wikipedia.org/wiki/Universally_unique_identifier) - /// * [RFC4122: A Universally Unique IDentifier (UUID) URN Namespace](http://tools.ietf.org/html/rfc4122) - #[Scalar(name = "UUID", specified_by_url = "http://tools.ietf.org/html/rfc4122")] - impl ScalarType for Uuid { - fn parse(value: Value) -> InputValueResult { - match value { - Value::String(s) => Ok(Uuid::from_str(&s)?), - _ => Err(InputValueError::expected_type(value)), - } - } - - fn to_value(&self) -> Value { - Value::String(self.to_string()) - } - } -}