Sha256: 8cd2f06dc455d28ee00ac8305ca5f53764e8205e280aa3652988497859163e99

Contents?: true

Size: 1.71 KB

Versions: 24

Compression:

Stored size: 1.71 KB

Contents

use std::{error, fmt};

/// An enumeration of buffer creation errors
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
    /// No choices were provided to the Unstructured::choose call
    EmptyChoose,
    /// There was not enough underlying data to fulfill some request for raw
    /// bytes.
    NotEnoughData,
    /// The input bytes were not of the right format
    IncorrectFormat,
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::EmptyChoose => write!(
                f,
                "`arbitrary::Unstructured::choose` must be given a non-empty set of choices"
            ),
            Error::NotEnoughData => write!(
                f,
                "There is not enough underlying raw data to construct an `Arbitrary` instance"
            ),
            Error::IncorrectFormat => write!(
                f,
                "The raw data is not of the correct format to construct this type"
            ),
        }
    }
}

impl error::Error for Error {}

/// A `Result` with the error type fixed as `arbitrary::Error`.
///
/// Either an `Ok(T)` or `Err(arbitrary::Error)`.
pub type Result<T, E = Error> = std::result::Result<T, E>;

#[cfg(test)]
mod tests {
    // Often people will import our custom `Result` type because 99.9% of
    // results in a file will be `arbitrary::Result` but then have that one last
    // 0.1% that want to have a custom error type. Don't make them prefix that
    // 0.1% as `std::result::Result`; instead, let `arbitrary::Result` have an
    // overridable error type.
    #[test]
    fn can_use_custom_error_types_with_result() -> super::Result<(), String> {
        Ok(())
    }
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/arbitrary-1.4.1/src/error.rs
wasmtime-29.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/error.rs
wasmtime-28.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/error.rs
wasmtime-27.0.0 ./ext/cargo-vendor/arbitrary-1.4.1/src/error.rs
wasmtime-26.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-25.0.2 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-25.0.1 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-25.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-24.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-23.0.2 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-22.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-21.0.1 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-20.0.2 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-20.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-18.0.3 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-17.0.1 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-17.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-16.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-15.0.1 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs
wasmtime-15.0.0 ./ext/cargo-vendor/arbitrary-1.3.2/src/error.rs