Geal / rust-syslog

Send syslog messages from Rust
MIT License
109 stars 55 forks source link

Make errors Send + Sync #65

Closed daviessm closed 1 month ago

daviessm commented 2 years ago

I'm unable to return errors from my syslog thread (not using the log framework) because the errors don't implement Sync:

                match syslog.info(alert_message)
                {
                    Ok(_) => Ok(()),
                    Err(e) => Err(Box::new(e)),
                }
error[E0277]: `(dyn StdError + std::marker::Send + 'static)` cannot be shared between threads safely
   --> src/alerts/common.rs:185:35
    |
185 |                     Err(e) => Err(Box::new(e)),
    |                               --- ^^^^^^^^^^^ `(dyn StdError + std::marker::Send + 'static)` cannot be shared between threads safely
    |                               |
    |                               required by a bound introduced by this call
    |
    = help: the trait `Sync` is not implemented for `(dyn StdError + std::marker::Send + 'static)`
    = note: required because of the requirements on the impl of `Sync` for `Unique<(dyn StdError + std::marker::Send + 'static)>`
    = note: required because it appears within the type `Box<(dyn StdError + std::marker::Send + 'static)>`
    = note: required because it appears within the type `std::option::Option<Box<(dyn StdError + std::marker::Send + 'static)>>`
    = note: required because it appears within the type `error_chain::State`
    = note: required because it appears within the type `syslog::Error`
    = note: required for the cast to the object type `dyn StdError + Sync + std::marker::Send`

Could the Sync trait be added?

Geal commented 1 month ago

fixed in #86 and tested in https://github.com/Geal/rust-syslog/commit/90e17aca36f9bc5c4cca6e9b6da995747e598e1a