| 1 | #[cfg(feature = "std")] |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 3 | |
| 4 | use thiserrorrust-analyzer cargo thiserror 2.0.16 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.16 Error:; |
| 5 | |
| 6 | use craterust-analyzer cargo bendy 0.6.1 crate/::state_trackerrust-analyzer cargo bendy 0.6.1 state_tracker/; |
| 7 | |
| 8 | /// An enumeration of potential errors that appear during bencode encoding. |
| 9 | #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Errorrust-analyzer cargo thiserror-impl 2.0.16 Error:)] |
| 10 | #[non_exhaustive] |
| 11 | pub enum Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error# { |
| 12 | /// Error that occurs if the serialized structure contains invalid semantics. |
| 13 | #[cfg(feature = "std")] |
| 14 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("malformed content discovered: {source}")] |
| 15 | MalformedContentrust-analyzer cargo bendy 0.6.1 encoding/error/Error#MalformedContent# { |
| 16 | sourcerust-analyzer cargo bendy 0.6.1 encoding/error/Error#MalformedContent#source.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<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# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>, |
| 17 | }, |
| 18 | |
| 19 | /// Error that occurs if the serialized structure contains invalid semantics. |
| 20 | #[cfg(not(feature = "std"))] |
| 21 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("malformed content discovered")] |
| 22 | MalformedContent, |
| 23 | |
| 24 | /// Error in the bencode structure (e.g. a missing field end separator). |
| 25 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("bencode encoding corrupted")] |
| 26 | StructureErrorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#StructureError# { |
| 27 | sourcerust-analyzer cargo bendy 0.6.1 encoding/error/Error#StructureError#source.: state_trackerrust-analyzer cargo bendy 0.6.1 state_tracker/::StructureErrorrust-analyzer cargo bendy 0.6.1 state_tracker/structure_error/StructureError#, |
| 28 | }, |
| 29 | } |
| 30 | |
| 31 | impl Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error# { |
| 32 | /// Raised when there is a general error while deserializing a type. |
| 33 | /// The message should not be capitalized and should not end with a period. |
| 34 | /// |
| 35 | /// Note that, when building with no_std, this method accepts any type as |
| 36 | /// its argument. |
| 37 | #[cfg(feature = "std")] |
| 38 | pub fn malformed_contentrust-analyzer cargo bendy 0.6.1 encoding/error/impl#[Error]malformed_content().<SourceT>(source: SourceT) -> Selfrust-analyzer cargo bendy 0.6.1 encoding/error/impl#[Error] |
| 39 | where |
| 40 | SourceT: 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# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static, |
| 41 | { |
| 42 | let error = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(source); |
| 43 | Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#::MalformedContentrust-analyzer cargo bendy 0.6.1 encoding/error/Error#MalformedContent# { sourcerust-analyzer cargo bendy 0.6.1 encoding/error/Error#MalformedContent#source.: error } |
| 44 | } |
| 45 | |
| 46 | #[cfg(not(feature = "std"))] |
| 47 | pub fn malformed_content<T>(_cause: T) -> Selfrust-analyzer cargo bendy 0.6.1 encoding/error/impl#[Error] { |
| 48 | Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#::MalformedContentrust-analyzer cargo bendy 0.6.1 encoding/error/Error#MalformedContent# |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<state_trackerrust-analyzer cargo bendy 0.6.1 state_tracker/::StructureErrorrust-analyzer cargo bendy 0.6.1 state_tracker/structure_error/StructureError#> for Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error# { |
| 53 | fn fromrust-analyzer cargo bendy 0.6.1 encoding/error/impl#[Error][`From<state_tracker::StructureError>`]from().(error: state_trackerrust-analyzer cargo bendy 0.6.1 state_tracker/::StructureErrorrust-analyzer cargo bendy 0.6.1 state_tracker/structure_error/StructureError#) -> Selfrust-analyzer cargo bendy 0.6.1 encoding/error/impl#[Error][`From<state_tracker::StructureError>`] { |
| 54 | Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#::StructureErrorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#StructureError# { sourcerust-analyzer cargo bendy 0.6.1 encoding/error/Error#StructureError#source.: error } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 59 | fn encoding_errors_are_sync_sendrust-analyzer cargo bendy 0.6.1 encoding/error/encoding_errors_are_sync_send().() { |
| 60 | use craterust-analyzer cargo bendy 0.6.1 crate/::encodingrust-analyzer cargo bendy 0.6.1 encoding/::errorrust-analyzer cargo bendy 0.6.1 encoding/error/::Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#; |
| 61 | fn is_sendrust-analyzer cargo bendy 0.6.1 encoding/error/is_send().<T: Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send#>() {} |
| 62 | fn is_syncrust-analyzer cargo bendy 0.6.1 encoding/error/is_sync().<T: Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync#>() {} |
| 63 | is_sendrust-analyzer cargo bendy 0.6.1 encoding/error/is_send().::<Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#>(); |
| 64 | is_syncrust-analyzer cargo bendy 0.6.1 encoding/error/is_sync().::<Errorrust-analyzer cargo bendy 0.6.1 encoding/error/Error#>(); |
| 65 | } |