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

feat: impl JsonTypdef for Url (behind a feature flag) #22

Merged
merged 3 commits into from
Feb 3, 2024

Conversation

tomkarw
Copy link
Contributor

@tomkarw tomkarw commented Feb 1, 2024

No description provided.

@uint
Copy link
Owner

uint commented Feb 1, 2024

This is something I need to think about. It's not exactly desirable for a library to add feature flags, and if we start implementing the trait for foreign types, I'm not sure where to draw the line.

@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 2, 2024

I get your point. However, it would definitely help with adoption.

Could you release a version with just the ordered field output? That's the one crucial for my use case.

@uint
Copy link
Owner

uint commented Feb 2, 2024

Could you release a version with just the ordered field output? That's the one crucial for my use case.

Yes. I'm currently traveling, but I'll try to get it done tomorrow.

@uint
Copy link
Owner

uint commented Feb 3, 2024

Okay, let's do it. I had a think and figured expecting jtd-derive users to use workarounds for popular types is hard to justify. I'll only agree to implementations for popular crates, which this is.

Cargo.toml Outdated
Comment on lines 14 to 17

[features]
url = ["dep:url"]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[features]
url = ["dep:url"]

I'm fairly sure this is unnecessary. The feature should be implicitly created bc of optional = true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

@uint uint self-requested a review February 3, 2024 19:04
@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 3, 2024

I think we should do it for all/most of structs in url i.e. Host, Origin, etc? I work on it today.

@uint
Copy link
Owner

uint commented Feb 3, 2024

I think we should do it for all/most of structs in url i.e. Host, Origin, etc? I work on it today.

schemars only implements the trait for Url - see here. I'm okay with adding others that are likely to be useful for JSON-based APIs and such.

(sorry about the edit - accident)

@uint
Copy link
Owner

uint commented Feb 3, 2024

BTW, any clues about why minimal_deps is failing? I'm scratching my head there.

Edit: probably unrelated, works for me locally. Happy to ignore it.

@tomkarw tomkarw force-pushed the impl-jsontypedef-for-url branch 2 times, most recently from 67c52b8 to b5de3e7 Compare February 3, 2024 19:27
@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 3, 2024

Any pointers on how to manually implement JsonTypedef for an enum? I'm struggling to implement it for url::Host to be precise.

@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 3, 2024

BTW, any clues about why minimal_deps is failing? I'm scratching my head there.

That's a funny one. cargo +nighlty update -Z minimal-versions also downgraded trybuild to 1.0.49 and apparently there was a bug in that version, which made the tests that rely on trybuild fail. Bumping the minimal version helped. Out of curiosity, I might bisect the 40 releases trybuild had to see what was the issue there.

@uint
Copy link
Owner

uint commented Feb 3, 2024

Any pointers on how to manually implement JsonTypedef for an enum? I'm struggling to implement it for url::Host to be precise.

Ah, it looks like Host uses the default externally tagged enum representation. JSON Typedef can't express that. I'm afraid we can't support it.

@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 3, 2024

I'm afraid we can't support it.

Alright. I'm happy to merge as-is, with just support for Url. Feel free to merge and release if you agree.


[dev-dependencies]
trybuild = "1.0.49"
trybuild = "1.0.89"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for diagnosing this!

@uint uint merged commit abed623 into uint:main Feb 3, 2024
5 checks passed
@uint
Copy link
Owner

uint commented Feb 3, 2024

It's all released!

@tomkarw tomkarw deleted the impl-jsontypedef-for-url branch February 3, 2024 21:56
@tomkarw
Copy link
Contributor Author

tomkarw commented Feb 3, 2024

Thanks for the quick dev cycle, it's not common in OSS 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants