Debian Codegraph @

src/error.rs

raw symbols SCIP
1
2 //! Error type definitions.
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
5 use 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#;
6 pub use 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# as IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#;
7 pub use 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/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result# as IoResultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#;
8 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#;
9 use 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/;
10 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/;
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::numrust-analyzer cargo std https://github.com/rust-lang/rust/library/std num/::TryFromIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/TryFromIntError#;
12
13
14 // Export types
15
16 /// A result that may contain an exr error.
17 pub type Resultrust-analyzer cargo exr 1.74.0 error/Result#<T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std 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 exr 1.74.0 error/Error#>;
18
19 /// A result that, if ok, contains nothing, and otherwise contains an exr error.
20 pub type UnitResultrust-analyzer cargo exr 1.74.0 error/UnitResult# = Resultrust-analyzer cargo exr 1.74.0 error/Result#<()>;
21
22
23 /// An error that may happen while reading or writing an exr file.
24 /// Distinguishes between three types of errors:
25 /// unsupported features, invalid data, and file system errors.
26 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
27 pub enum Errorrust-analyzer cargo exr 1.74.0 error/Error# {
28
29 /// Reading or Writing the file has been aborted by the caller.
30 /// This error will never be triggered by this crate itself,
31 /// only by users of this library.
32 /// It exists to be returned from a progress callback.
33 Abortedrust-analyzer cargo exr 1.74.0 error/Error#Aborted#, // FIXME remove?? is not used really?
34
35 /// The contents of the file are not supported by
36 /// this specific implementation of open exr,
37 /// even though the data may be valid.
38 NotSupportedrust-analyzer cargo exr 1.74.0 error/Error#NotSupported#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>),
39
40 /// The contents of the image are contradicting or insufficient.
41 /// Also returned for `ErrorKind::UnexpectedEof` errors.
42 Invalidrust-analyzer cargo exr 1.74.0 error/Error#Invalid#(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>),
43
44 /// The underlying byte stream could not be read successfully,
45 /// probably due to file system related errors.
46 Iorust-analyzer cargo exr 1.74.0 error/Error#Io#(IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#),
47 }
48
49
50 impl Errorrust-analyzer cargo exr 1.74.0 error/Error# {
51
52 /// Create an error of the variant `Invalid`.
53 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(message: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>>) -> Selfrust-analyzer cargo exr 1.74.0 error/impl#[Error] {
54 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Invalidrust-analyzer cargo exr 1.74.0 error/Error#Invalid#(message.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())
55 }
56
57 /// Create an error of the variant `NotSupported`.
58 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn unsupportedrust-analyzer cargo exr 1.74.0 error/impl#[Error]unsupported().(message: impl Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, str>>) -> Selfrust-analyzer cargo exr 1.74.0 error/impl#[Error] {
59 Errorrust-analyzer cargo exr 1.74.0 error/Error#::NotSupportedrust-analyzer cargo exr 1.74.0 error/Error#NotSupported#(message.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().())
60 }
61 }
62
63 /// Enable using the `?` operator on `std::io::Result`.
64 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for Errorrust-analyzer cargo exr 1.74.0 error/Error# {
65 fn fromrust-analyzer cargo exr 1.74.0 error/impl#[Error][`From<IoError>`]from().(error: IoErrorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> Selfrust-analyzer cargo exr 1.74.0 error/impl#[Error][`From<IoError>`] {
66 if error.kindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]kind().() rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[ErrorKind][`PartialEq<Self>`]eq().ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof# {
67 Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("reference to missing bytes")
68 }
69 else {
70 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Iorust-analyzer cargo exr 1.74.0 error/Error#Io#(error)
71 }
72 }
73 }
74
75 // TODO use `usize::try_from(x)?` everywhere
76 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<TryFromIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/TryFromIntError#> for Errorrust-analyzer cargo exr 1.74.0 error/Error# {
77 fn fromrust-analyzer cargo exr 1.74.0 error/impl#[Error][`From<TryFromIntError>`]from().(_: TryFromIntErrorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/error/TryFromIntError#) -> Selfrust-analyzer cargo exr 1.74.0 error/impl#[Error][`From<TryFromIntError>`] {
78 Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().("invalid size")
79 }
80 }
81
82 impl 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# for Errorrust-analyzer cargo exr 1.74.0 error/Error# {
83 fn sourcerust-analyzer cargo exr 1.74.0 error/impl#[Error][Error]source().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&(dyn 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# + 'static)> {
84 match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self {
85 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Iorust-analyzer cargo exr 1.74.0 error/Error#Io#(ref err) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(err),
86 _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
87 }
88 }
89 }
90
91 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Errorrust-analyzer cargo exr 1.74.0 error/Error# {
92 fn fmtrust-analyzer cargo exr 1.74.0 error/impl#[Error][Display]fmt().(&self, formatter: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
93 match self {
94 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Iorust-analyzer cargo exr 1.74.0 error/Error#Io#(err) => err.fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][Display]fmt().(formatter),
95 Errorrust-analyzer cargo exr 1.74.0 error/Error#::NotSupportedrust-analyzer cargo exr 1.74.0 error/Error#NotSupported#(message) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "not supported: {}", message),
96 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Invalidrust-analyzer cargo exr 1.74.0 error/Error#Invalid#(message) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "invalid: {}", message),
97 Errorrust-analyzer cargo exr 1.74.0 error/Error#::Abortedrust-analyzer cargo exr 1.74.0 error/Error#Aborted# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "cancelled"),
98 }
99 }
100 }
101
102 /// Typically used during decoding. Return error on invalid range.
103 #[inline]
104 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn i32_to_usizerust-analyzer cargo exr 1.74.0 error/i32_to_usize().(value: i32, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<usize> {
105 usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<i32>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| {
106 if value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 { Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(error_message) }
107 else { Errorrust-analyzer cargo exr 1.74.0 error/Error#::unsupportedrust-analyzer cargo exr 1.74.0 error/impl#[Error]unsupported().(error_message) }
108 })
109 }
110
111 /// Typically used during encoding. Return error on overflow.
112 #[inline]
113 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn usize_to_u32rust-analyzer cargo exr 1.74.0 error/usize_to_u32().(value: usize, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<u32> {
114 u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u32][`TryFrom<usize>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(error_message))
115 }
116
117 /// Typically used during encoding. Return error on invalid range.
118 #[inline]
119 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn usize_to_u16rust-analyzer cargo exr 1.74.0 error/usize_to_u16().(value: usize, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<u16> {
120 u16::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u16][`TryFrom<usize>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(error_message))
121 }
122
123 /// Typically used during decoding. Return error on invalid range.
124 #[inline]
125 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn u64_to_usizerust-analyzer cargo exr 1.74.0 error/u64_to_usize().(value: u64, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<usize> {
126 usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u64>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::unsupportedrust-analyzer cargo exr 1.74.0 error/impl#[Error]unsupported().(error_message))
127 }
128
129 /// Typically used during decoding. Return error on invalid range.
130 #[inline]
131 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn u32_to_usizerust-analyzer cargo exr 1.74.0 error/u32_to_usize().(value: u32, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<usize> {
132 usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u32>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::unsupportedrust-analyzer cargo exr 1.74.0 error/impl#[Error]unsupported().(error_message))
133 }
134
135 /// Typically used during encoding. Return error on invalid range.
136 #[inline]
137 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn usize_to_i32rust-analyzer cargo exr 1.74.0 error/usize_to_i32().(value: usize, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<i32> {
138 i32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[i32][`TryFrom<usize>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(error_message))
139 }
140
141 /// Typically used during encoding. Return error on invalid range.
142 #[inline]
143 pub(craterust-analyzer cargo exr 1.74.0 crate/) fn usize_to_u64rust-analyzer cargo exr 1.74.0 error/usize_to_u64().(value: usize, error_message: &'static str) -> Resultrust-analyzer cargo exr 1.74.0 error/Result#<u64> {
144 u64::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u64][`TryFrom<usize>`]try_from().(value).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| Errorrust-analyzer cargo exr 1.74.0 error/Error#::invalidrust-analyzer cargo exr 1.74.0 error/impl#[Error]invalid().(error_message))
145 }