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

FieldMutability is missing Parse and ToTokens #1717

Open
programmerjake opened this issue Aug 10, 2024 · 1 comment
Open

FieldMutability is missing Parse and ToTokens #1717

programmerjake opened this issue Aug 10, 2024 · 1 comment

Comments

@programmerjake
Copy link
Contributor

I'm trying to write future-proof code that asserts matches!(field.mutability, FieldMutability::None) and reports a nice error if it isn't None:

let Field { mutability, .. } = &mut field;
if !matches!(mutability, FieldMutability::None) {
    errors.push(syn::Error::new_spanned(mutability, "field mutability is not supported"));
    *mutability = FieldMutability::None;
}

but that doesn't work because FieldMutability doesn't implement ToTokens.
Please add a ToTokens implementation. Adding a Parse implementation while you're at it would be nice.

@Fancyflame
Copy link
Contributor

Have you considered using Span::call_site() as a temporary substitute, or the span of the whole field?

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

No branches or pull requests

2 participants