Skip to content

Derive attribute for items implement FromStr and ToString #585

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

Open
tversteeg opened this issue May 12, 2025 · 1 comment
Open

Derive attribute for items implement FromStr and ToString #585

tversteeg opened this issue May 12, 2025 · 1 comment
Labels
📜 derive Related to the derive macro ✨ enhancement New feature or request

Comments

@tversteeg
Copy link
Contributor

While implementing the jiff types, I noticed that a lot of Facet implementations can be easily created if they implement core::str::FromStr and core::fmt::Display.

So I was thinking maybe add an attribute to the derive macro to simplify this?

Something like:

#[derive(Facet)]
#[facet(as_string)]
struct MyType {
  ..
}

impl Display for MyType {
  ..
}

impl FromStr for MyType {
 ..
}

Not entirely sure about the as_string naming.

@tversteeg tversteeg added ✨ enhancement New feature or request 📜 derive Related to the derive macro labels May 12, 2025
@kylewlacy
Copy link
Contributor

I would definitely like something like this for de/serialization! In the Serde world, this isn't something natively supported, so there are at least a few third-party crates to help bridge between Display/FromStr and Serde impls (serde_with is the one I am most familiar with)

Internally, for facet-serialize, this match statement feels like it would do better if it could just check "does this shape have the as_string shape attribute?" or something, instead of special-casing a few shape affinities

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 derive Related to the derive macro ✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants