Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add derive support for std::net::IpAddr which serializes as String #29

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
e: Test8,
f: Option<Test9>,
g: (),
h: std::net::IpAddr,
},
C(Parent),
D,
Expand Down Expand Up @@ -236,6 +237,7 @@
"E": types.TEST_8;
"F": (types.Test9 | null);
"G": null;
"H": string;
};
} | {
"type": "C";
Expand All @@ -257,6 +259,7 @@

#[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 @@
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 Expand Up @@ -655,7 +659,7 @@
#[test]
fn generics() {
#[derive(Serialize, TypeDef)]
struct Test<'a, A>

Check warning on line 662 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Test

unnecessary lifetime parameter `'a`

Check warning on line 662 in tests/test.rs

View workflow job for this annotation

GitHub Actions / Lint

unnecessary lifetime parameter `'a`
where
A: fmt::Display,
{
Expand Down