arbitrary_int/
lib.rs

1// By unconditionally declaring this crate as `no_std` we opt out of the standard library's prelude,
2// which implicitly brings items like `Vec` and `String` into scope. Since we'd need to import those
3// manually in case the `alloc` crate is used but the standard library isn't, we might as well keep
4// things consistent and always manually import them.
5#![no_std]
6#![cfg_attr(
7    feature = "const_convert_and_const_trait_impl",
8    feature(const_convert, const_trait_impl, inline_const)
9)]
10#![cfg_attr(feature = "step_trait", feature(step_trait))]
11
12// This makes it possible to use `std::` when the `std` feature is enabled, even though we're `no_std`.
13#[cfg(feature = "std")]
14extern crate std;
15
16// The `alloc` crate is always usable when the standard library (i.e. the `std` feature) is enabled.
17// The standard library re-exports collections from the `alloc` crate, but since this crate supports
18// `alloc` without `std` its best to use `alloc` directly: that works both with and without `std`.
19#[cfg(any(feature = "borsh", feature = "std"))]
20extern crate alloc;
21
22use core::fmt;
23
24mod common;
25mod signed;
26pub mod traits;
27mod unsigned;
28mod v1_number_compat;
29
30pub use signed::*;
31pub use unsigned::*;
32pub use v1_number_compat::*;
33
34/// The preferred way to import arbitrary-int into a project: `use arbitrary_int::prelude::*`
35pub mod prelude {
36    pub use crate::signed::*;
37    pub use crate::traits::*;
38    pub use crate::unsigned::*;
39    pub use crate::TryNewError;
40}
41
42#[cfg(feature = "arbitrary")]
43mod arbitrary;
44
45#[cfg(feature = "quickcheck")]
46mod quickcheck;
47
48#[derive(Debug, Clone, Eq, PartialEq)]
49pub struct TryNewError;
50
51impl fmt::Display for TryNewError {
52    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
53        write!(f, "Value too large to fit within this integer type")
54    }
55}