kenianbei / vcard_parser

Parses and validates vCard data according to RFC 6350 specification.
MIT License
6 stars 3 forks source link

feat: implement std::error::Error for VcardError: #17

Closed Cyrix126 closed 9 months ago

Cyrix126 commented 10 months ago

First, a big thank you for rewriting this splendid library !

I want to make this very small contribution.

Default implementation of std::error::Error for VcardError. Allow the use of the operator '?' to propagate the error of this crate in a more generic way.

For example, this code would compile with this patch.

use std::error::Error;
use vcard_parser::parse_vcards;

fn main() -> Result<(), Box<dyn Error>> {
    parse_vcards("")?;
    Ok(())
}

Without this patch, the compilation fails:

 --> src/main.rs:5:21
  |
5 |     parse_vcards("")?;
  |                     ^ the trait `std::error::Error` is not implemented for `VcardError`
  |
  = help: the following other types implement trait `FromResidual<R>`:
            <Result<T, F> as FromResidual<Result<Infallible, E>>>
            <Result<T, F> as FromResidual<Yeet<E>>>
  = note: required for `Box<dyn std::error::Error>` to implement `From<VcardError>`
  = note: required for `Result<(), Box<dyn std::error::Error>>` to implement `FromResidual<Result<Infallible, VcardError>>`

For more information about this error, try `rustc --explain E0277`.