| 1 | //! Error types used and generated by Calloop. |
| 2 | //! |
| 3 | //! This module contains error types for Calloop's operations. They are designed |
| 4 | //! to make it easy to deal with errors arising from Calloop's internal I/O and |
| 5 | //! other operations. |
| 6 | //! |
| 7 | //! There are two top-level error types: |
| 8 | //! |
| 9 | //! - [`Error`]: used by callback functions, internal operations, and some event |
| 10 | //! loop API calls |
| 11 | //! |
| 12 | //! - [`InsertError`]: used primarily by the [`insert_source()`] method when an |
| 13 | //! event source cannot be added to the loop and needs to be given back to the |
| 14 | //! caller |
| 15 | //! |
| 16 | //! [`insert_source()`]: crate::LoopHandle::insert_source() |
| 17 | |
| 18 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#}; |
| 19 | |
| 20 | /// The primary error type used by Calloop covering internal errors and I/O |
| 21 | /// errors that arise during loop operations such as source registration or |
| 22 | /// event dispatching. |
| 23 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 1.0.7 crate/::Errorrust-analyzer cargo thiserror-impl 1.0.7 Error:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 24 | pub enum Errorrust-analyzer cargo calloop 0.10.5 error/Error# { |
| 25 | /// When an event source is registered (or re- or un-registered) with the |
| 26 | /// event loop, this error variant will occur if the token Calloop uses to |
| 27 | /// keep track of the event source is not valid. |
| 28 | #[errorrust-analyzer cargo thiserror-impl 1.0.7 error:("invalid token provided to internal function")] |
| 29 | InvalidTokenrust-analyzer cargo calloop 0.10.5 error/Error#InvalidToken#, |
| 30 | |
| 31 | /// This variant wraps a [`std::io::Error`], which might arise from |
| 32 | /// Calloop's internal operations. |
| 33 | #[errorrust-analyzer cargo thiserror-impl 1.0.7 error:("underlying IO error")] |
| 34 | IoErrorrust-analyzer cargo calloop 0.10.5 error/Error#IoError#(#[from] stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 35 | |
| 36 | /// Any other unexpected error kind (most likely from a user implementation of |
| 37 | /// [`EventSource::process_events()`]) will be wrapped in this. |
| 38 | /// |
| 39 | /// [`EventSource::process_events()`]: crate::EventSource::process_events() |
| 40 | #[errorrust-analyzer cargo thiserror-impl 1.0.7 error:("other error during loop operation")] |
| 41 | OtherErrorrust-analyzer cargo calloop 0.10.5 error/Error#OtherError#(#[from] Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<dyn stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>), |
| 42 | } |
| 43 | |
| 44 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<nixrust-analyzer cargo nix 0.30.1 crate/::errnorust-analyzer cargo nix 0.30.1 errno/::Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#> for Errorrust-analyzer cargo calloop 0.10.5 error/Error# { |
| 45 | /// Converts a [`nix::Error`] into a wrapped version of the equivalent |
| 46 | /// [`std::io::Error`]. |
| 47 | fn fromrust-analyzer cargo calloop 0.10.5 error/impl#[Error][`From<nix::errno::Errno>`]from().(err: nixrust-analyzer cargo nix 0.30.1 crate/::errnorust-analyzer cargo nix 0.30.1 errno/::Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#) -> Selfrust-analyzer cargo calloop 0.10.5 error/impl#[Error][`From<nix::errno::Errno>`] { |
| 48 | Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#>::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(err).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Errorrust-analyzer cargo calloop 0.10.5 error/Error#> for stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# { |
| 53 | /// Converts Calloop's error type into a [`std::io::Error`]. |
| 54 | fn fromrust-analyzer cargo calloop 0.10.5 error/impl#[`std::io::Error`][`From<Error>`]from().(err: Errorrust-analyzer cargo calloop 0.10.5 error/Error#) -> Selfrust-analyzer cargo calloop 0.10.5 error/impl#[`std::io::Error`][`From<Error>`] { |
| 55 | match err { |
| 56 | Errorrust-analyzer cargo calloop 0.10.5 error/Error#::IoErrorrust-analyzer cargo calloop 0.10.5 error/Error#IoError#(source) => source, |
| 57 | Errorrust-analyzer cargo calloop 0.10.5 error/Error#::InvalidTokenrust-analyzer cargo calloop 0.10.5 error/Error#InvalidToken# => Selfrust-analyzer cargo calloop 0.10.5 error/impl#[`std::io::Error`][`From<Error>`]::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidInputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidInput#, err.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 58 | Errorrust-analyzer cargo calloop 0.10.5 error/Error#::OtherErrorrust-analyzer cargo calloop 0.10.5 error/Error#OtherError#(source) => Selfrust-analyzer cargo calloop 0.10.5 error/impl#[`std::io::Error`][`From<Error>`]::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, source), |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /// [`Result`] alias using Calloop's error type. |
| 64 | pub type Resultrust-analyzer cargo calloop 0.10.5 error/Result#<T> = corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo calloop 0.10.5 error/Error#>; |
| 65 | |
| 66 | /// An error generated when trying to insert an event source |
| 67 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 1.0.7 crate/::Errorrust-analyzer cargo thiserror-impl 1.0.7 Error:)] |
| 68 | #[error("error inserting event source")] |
| 69 | pub struct InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#<T> { |
| 70 | /// The source that could not be inserted |
| 71 | pub insertedrust-analyzer cargo calloop 0.10.5 error/InsertError#inserted.: T, |
| 72 | /// The generated error |
| 73 | #[sourcerust-analyzer cargo thiserror-impl 1.0.7 source:] |
| 74 | pub errorrust-analyzer cargo calloop 0.10.5 error/InsertError#error.: Errorrust-analyzer cargo calloop 0.10.5 error/Error#, |
| 75 | } |
| 76 | |
| 77 | impl<T> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#<T> { |
| 78 | #[cfg_attr(coverage, no_coverage)] |
| 79 | fn fmtrust-analyzer cargo calloop 0.10.5 error/impl#[`InsertError<T>`][Debug]fmt().(&self, formatter: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#> { |
| 80 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "{:?}", self.errorrust-analyzer cargo calloop 0.10.5 error/InsertError#error.) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | impl<T> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#<T>> for craterust-analyzer cargo calloop 0.10.5 crate/::Errorrust-analyzer cargo calloop 0.10.5 error/Error# { |
| 85 | /// Converts the [`InsertError`] into Calloop's error type, throwing away |
| 86 | /// the contained source. |
| 87 | #[cfg_attr(coverage, no_coverage)] |
| 88 | fn fromrust-analyzer cargo calloop 0.10.5 error/impl#[Error][`From<InsertError<T>>`]from().(e: InsertErrorrust-analyzer cargo calloop 0.10.5 error/InsertError#<T>) -> craterust-analyzer cargo calloop 0.10.5 crate/::Errorrust-analyzer cargo calloop 0.10.5 error/Error# { |
| 89 | e.errorrust-analyzer cargo calloop 0.10.5 error/InsertError#error. |
| 90 | } |
| 91 | } |