Skip to content

Simple crate to more easily work with an optional syn::Error

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

MrGVSV/optional-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

optional-error

crates.io docs.rs

This crate provides a simpler way to create and manage an Option<syn::Error>.

fn parse(input: DeriveInput) -> Result<TokenStream, syn::Error> {
    // Create an optional error to contain zero or more errors
    let mut errors = OptionalError::default();

    if !matches!(input.vis, Visibility::Public(_)) {
        // Combine with a new error (or initialize if empty)
        errors.combine(syn::Error::new(Span::call_site(), "input must be marked `pub`"));
    }

    match input.data {
        syn::Data::Struct(_) | syn::Data::Enum(_) => { /* ... */ }
        syn::Data::Union(_) => {
            // Combine some more!
            errors.combine(syn::Error::new(Span::call_site(), "unions not supported"));
        }
    }

    // Easy early return with all errors (if any)
    errors.try_throw()?;

    // ...
}

About

Simple crate to more easily work with an optional syn::Error

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages