impl Display for ID (#783)

This commit is contained in:
Stijn Frishert 2020-10-10 16:17:33 +02:00 committed by GitHub
parent 746aff34a5
commit 68210f54ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,6 @@
use std::{char, convert::From, marker::PhantomData, ops::Deref, rc::Rc, thread::JoinHandle, u32};
use std::{
char, convert::From, fmt, marker::PhantomData, ops::Deref, rc::Rc, thread::JoinHandle, u32,
};
use serde::{Deserialize, Serialize};
@ -42,6 +44,12 @@ impl Deref for ID {
}
}
impl fmt::Display for ID {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(f)
}
}
#[crate::graphql_scalar(name = "ID")]
impl<S> GraphQLScalar for ID
where
@ -488,6 +496,12 @@ mod tests {
assert_eq!(id.len(), 3);
}
#[test]
fn test_id_display() {
let id = ID(String::from("foo"));
assert_eq!(format!("{}", id), "foo");
}
#[test]
fn parse_strings() {
fn parse_string(s: &str, expected: &str) {