Skip to content

Commit 68210f5

Browse files
impl Display for ID (#783)
1 parent 746aff3 commit 68210f5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

juniper/src/types/scalars.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use std::{char, convert::From, marker::PhantomData, ops::Deref, rc::Rc, thread::JoinHandle, u32};
1+
use std::{
2+
char, convert::From, fmt, marker::PhantomData, ops::Deref, rc::Rc, thread::JoinHandle, u32,
3+
};
24

35
use serde::{Deserialize, Serialize};
46

@@ -42,6 +44,12 @@ impl Deref for ID {
4244
}
4345
}
4446

47+
impl fmt::Display for ID {
48+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49+
self.0.fmt(f)
50+
}
51+
}
52+
4553
#[crate::graphql_scalar(name = "ID")]
4654
impl<S> GraphQLScalar for ID
4755
where
@@ -488,6 +496,12 @@ mod tests {
488496
assert_eq!(id.len(), 3);
489497
}
490498

499+
#[test]
500+
fn test_id_display() {
501+
let id = ID(String::from("foo"));
502+
assert_eq!(format!("{}", id), "foo");
503+
}
504+
491505
#[test]
492506
fn parse_strings() {
493507
fn parse_string(s: &str, expected: &str) {

0 commit comments

Comments
 (0)