optional-error

Crates.iooptional-error
lib.rsoptional-error
version0.1.1
sourcesrc
created_at2023-03-13 02:14:03.96985
updated_at2023-03-13 02:16:12.856417
descriptionSimple crate to more easily work with an optional syn::Error
homepage
repositoryhttps://github.com/MrGVSV/optional-error
max_upload_size
id808460
size23,198
Gino Valente (MrGVSV)

documentation

README

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()?;

    // ...
}
Commit count: 5

cargo fmt