Skip to content

Commit

Permalink
Merge pull request #29 from gregor-netdebug/ipaddr-support
Browse files Browse the repository at this point in the history
Add derive support for std::net::IpAddr which serializes as String
  • Loading branch information
dbeckwith authored Nov 28, 2023
2 parents 1573624 + 0700e5b commit 321cf49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl_native!(std::ffi::OsString, "string");
impl_native!(std::ffi::OsStr, "string");
#[cfg(feature = "json_value")]
impl_native!(serde_json::Number, "number");
impl_native!(std::net::IpAddr, "string");

macro_rules! impl_number {
($ty:ty, $name:ident) => {
Expand Down
6 changes: 5 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ mod derive {
e: Test8,
f: Option<Test9>,
g: (),
h: std::net::IpAddr,
},
C(Parent),
D,
Expand Down Expand Up @@ -236,6 +237,7 @@ export namespace types {
"E": types.TEST_8;
"F": (types.Test9 | null);
"G": null;
"H": string;
};
} | {
"type": "C";
Expand All @@ -257,6 +259,7 @@ export namespace types {

#[test]
fn json() {
use std::str::FromStr;
assert_eq_str!(
serde_json::to_string(&Test10::B {
a: Test4::A(Test3(Test2(
Expand All @@ -281,9 +284,10 @@ export namespace types {
e: Test8 {},
f: None,
g: (),
h: std::net::IpAddr::from_str("::1").unwrap(),
})
.unwrap(),
r#"{"type":"B","value":{"A":[{"FOO_BAR":123,"a":"foo","b":null,"c":[true,false],"FFF":"f","g":{"Ok":"test"},"h":{"Err":1234},"i":["test"]},4,"bar"],"B":"cool-beans","C":{"B":[42,"baz"]},"D":null,"E":{},"F":null,"G":null}}"#
r#"{"type":"B","value":{"A":[{"FOO_BAR":123,"a":"foo","b":null,"c":[true,false],"FFF":"f","g":{"Ok":"test"},"h":{"Err":1234},"i":["test"]},4,"bar"],"B":"cool-beans","C":{"B":[42,"baz"]},"D":null,"E":{},"F":null,"G":null,"H":"::1"}}"#
);
}

Expand Down

0 comments on commit 321cf49

Please sign in to comment.