| 1 |
// These links overwrite the ones in `README.md` |
| 2 |
// to become proper intra-doc links in Rust docs. |
| 3 |
//! [`From`]: crate::From |
| 4 |
//! [`Into`]: crate::Into |
| 5 |
//! [`FromStr`]: crate::FromStr |
| 6 |
//! [`TryInto`]: crate::TryInto |
| 7 |
//! [`IntoIterator`]: crate::IntoIterator |
| 8 |
//! [`AsRef`]: crate::AsRef |
| 9 |
//! |
| 10 |
//! [`Debug`]: crate::Debug |
| 11 |
//! [`Display`-like]: crate::Display |
| 12 |
//! |
| 13 |
//! [`Error`]: crate::Error |
| 14 |
//! |
| 15 |
//! [`Index`]: crate::Index |
| 16 |
//! [`Deref`]: crate::Deref |
| 17 |
//! [`Not`-like]: crate::Not |
| 18 |
//! [`Add`-like]: crate::Add |
| 19 |
//! [`Mul`-like]: crate::Mul |
| 20 |
//! [`Sum`-like]: crate::Sum |
| 21 |
//! [`IndexMut`]: crate::IndexMut |
| 22 |
//! [`DerefMut`]: crate::DerefMut |
| 23 |
//! [`AddAssign`-like]: crate::AddAssign |
| 24 |
//! [`MulAssign`-like]: crate::MulAssign |
| 25 |
//! |
| 26 |
//! [`Constructor`]: crate::Constructor |
| 27 |
//! [`IsVariant`]: crate::IsVariant |
| 28 |
//! [`Unwrap`]: crate::Unwrap |
| 29 |
//! [`TryUnwrap`]: crate::TryUnwrap |
| 30 |
|
| 31 |
// The README includes doctests requiring these features. To make sure that |
| 32 |
// tests pass when not all features are provided we exclude it when the |
| 33 |
// required features are not available. |
| 34 |
#![cfg_attr( |
| 35 |
all( |
| 36 |
feature = "add", |
| 37 |
feature = "display", |
| 38 |
feature = "from", |
| 39 |
feature = "into" |
| 40 |
), |
| 41 |
doc = include_str!("../README.md") |
| 42 |
)] |
| 43 |
#![cfg_attr(not(feature = "std"), no_std)] |
| 44 |
#![cfg_attr(all(not(feature = "std"), feature = "error"), feature(error_in_core))] |
| 45 |
#![cfg_attr(docsrs, feature(doc_auto_cfg))] |
| 46 |
#![cfg_attr(any(not(docsrs), ci), deny(rustdoc::all))] |
| 47 |
#![forbid(non_ascii_idents, unsafe_code)] |
| 48 |
#![warn(clippy::nonstandard_macro_braces)] |
| 49 |
|
| 50 |
// Not public, but exported API. For macro expansion internals only. |
| 51 |
#[doc(hidden)] |
| 52 |
pub mod __private { |
| 53 |
#[cfg(feature = "debug")] |
| 54 |
pub use crate::fmt::{debug_tuple, DebugTuple}; |
| 55 |
|
| 56 |
#[cfg(feature = "error")] |
| 57 |
pub use crate::vendor::thiserror::aserror::AsDynError; |
| 58 |
} |
| 59 |
|
| 60 |
// The modules containing error types and other helpers |
| 61 |
#[cfg(any(feature = "add", feature = "not"))] |
| 62 |
pub mod ops; |
| 63 |
|
| 64 |
#[cfg(feature = "debug")] |
| 65 |
mod fmt; |
| 66 |
|
| 67 |
#[cfg(feature = "error")] |
| 68 |
mod vendor; |
| 69 |
|
| 70 |
#[cfg(feature = "from_str")] |
| 71 |
mod r#str; |
| 72 |
#[cfg(feature = "from_str")] |
| 73 |
#[doc(inline)] |
| 74 |
pub use crate::r#str::FromStrError; |
| 75 |
|
| 76 |
#[cfg(feature = "try_into")] |
| 77 |
mod convert; |
| 78 |
#[cfg(feature = "try_into")] |
| 79 |
#[doc(inline)] |
| 80 |
pub use crate::convert::TryIntoError; |
| 81 |
|
| 82 |
#[cfg(feature = "try_unwrap")] |
| 83 |
mod try_unwrap; |
| 84 |
#[cfg(feature = "try_unwrap")] |
| 85 |
#[doc(inline)] |
| 86 |
pub use self::try_unwrap::TryUnwrapError; |
| 87 |
|
| 88 |
// When re-exporting traits from std we need to do a pretty crazy trick, because we ONLY want |
| 89 |
// to re-export the traits and not derives that are called the same in the std module, |
| 90 |
// because those would conflict with our own. The way we do this is by first importing both |
| 91 |
// the trait and possible derive into a separate module and re-export them. Then we wildcard import |
| 92 |
// all the things from that module into the main module, but we also import our own derive by its |
| 93 |
// exact name. Due to the way wildcard imports work in rust, that results in our own derive taking |
| 94 |
// precedence over any derive from std. For some reason the named re-export of our own derive |
| 95 |
// cannot be in in this (or really any) macro too. It will somehow still consider it a wildcard |
| 96 |
// then and will result in this warning ambiguous_glob_reexports, and not actually exporting of our |
| 97 |
// derive. |
| 98 |
macro_rules! re_export_traits(( |
| 99 |
$feature:literal, $new_module_name:ident, $module:path $(, $traits:ident)* $(,)?) => { |
| 100 |
#[cfg(feature = $feature)] |
| 101 |
mod $new_module_name { |
| 102 |
pub use $module::{$($traits),*}; |
| 103 |
} |
| 104 |
|
| 105 |
#[cfg(feature = $feature)] |
| 106 |
#[doc(hidden)] |
| 107 |
pub use crate::$new_module_name::*; |
| 108 |
|
| 109 |
} |
| 110 |
); |
| 111 |
|
| 112 |
re_export_traits!( |
| 113 |
"add", |
| 114 |
add_traits, |
| 115 |
core::ops, |
| 116 |
Add, |
| 117 |
BitAnd, |
| 118 |
BitOr, |
| 119 |
BitXor, |
| 120 |
Sub, |
| 121 |
); |
| 122 |
re_export_traits!( |
| 123 |
"add_assign", |
| 124 |
add_assign_traits, |
| 125 |
core::ops, |
| 126 |
AddAssign, |
| 127 |
BitAndAssign, |
| 128 |
BitOrAssign, |
| 129 |
BitXorAssign, |
| 130 |
SubAssign, |
| 131 |
); |
| 132 |
re_export_traits!("as_mut", as_mut_traits, core::convert, AsMut); |
| 133 |
re_export_traits!("as_ref", as_ref_traits, core::convert, AsRef); |
| 134 |
re_export_traits!("debug", debug_traits, core::fmt, Debug); |
| 135 |
re_export_traits!("deref", deref_traits, core::ops, Deref); |
| 136 |
re_export_traits!("deref_mut", deref_mut_traits, core::ops, DerefMut); |
| 137 |
re_export_traits!( |
| 138 |
"display", |
| 139 |
display_traits, |
| 140 |
core::fmt, |
| 141 |
Binary, |
| 142 |
Display, |
| 143 |
LowerExp, |
| 144 |
LowerHex, |
| 145 |
Octal, |
| 146 |
Pointer, |
| 147 |
UpperExp, |
| 148 |
UpperHex, |
| 149 |
); |
| 150 |
|
| 151 |
#[cfg(not(feature = "std"))] |
| 152 |
re_export_traits!("error", error_traits, core::error, Error); |
| 153 |
#[cfg(feature = "std")] |
| 154 |
re_export_traits!("error", error_traits, std::error, Error); |
| 155 |
|
| 156 |
re_export_traits!("from", from_traits, core::convert, From); |
| 157 |
|
| 158 |
re_export_traits!("from_str", from_str_traits, core::str, FromStr); |
| 159 |
|
| 160 |
re_export_traits!("index", index_traits, core::ops, Index); |
| 161 |
|
| 162 |
re_export_traits!("index_mut", index_mut_traits, core::ops, IndexMut); |
| 163 |
|
| 164 |
re_export_traits!("into", into_traits, core::convert, Into); |
| 165 |
|
| 166 |
re_export_traits!( |
| 167 |
"into_iterator", |
| 168 |
into_iterator_traits, |
| 169 |
core::iter, |
| 170 |
IntoIterator, |
| 171 |
); |
| 172 |
|
| 173 |
re_export_traits!("mul", mul_traits, core::ops, Div, Mul, Rem, Shl, Shr); |
| 174 |
|
| 175 |
#[cfg(feature = "mul_assign")] |
| 176 |
re_export_traits!( |
| 177 |
"mul_assign", |
| 178 |
mul_assign_traits, |
| 179 |
core::ops, |
| 180 |
DivAssign, |
| 181 |
MulAssign, |
| 182 |
RemAssign, |
| 183 |
ShlAssign, |
| 184 |
ShrAssign, |
| 185 |
); |
| 186 |
|
| 187 |
re_export_traits!("not", not_traits, core::ops, Neg, Not); |
| 188 |
|
| 189 |
re_export_traits!("sum", sum_traits, core::iter, Product, Sum); |
| 190 |
|
| 191 |
re_export_traits!("try_into", try_into_traits, core::convert, TryInto); |
| 192 |
|
| 193 |
// Now re-export our own derives by their exact name to overwrite any derives that the trait |
| 194 |
// re-exporting might inadvertently pull into scope. |
| 195 |
#[cfg(feature = "add")] |
| 196 |
pub use derive_more_impl::{Add, BitAnd, BitOr, BitXor, Sub}; |
| 197 |
|
| 198 |
#[cfg(feature = "add_assign")] |
| 199 |
pub use derive_more_impl::{ |
| 200 |
AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, SubAssign, |
| 201 |
}; |
| 202 |
|
| 203 |
#[cfg(feature = "as_mut")] |
| 204 |
pub use derive_more_impl::AsMut; |
| 205 |
|
| 206 |
#[cfg(feature = "as_ref")] |
| 207 |
pub use derive_more_impl::AsRef; |
| 208 |
|
| 209 |
#[cfg(feature = "constructor")] |
| 210 |
pub use derive_more_impl::Constructor; |
| 211 |
|
| 212 |
#[cfg(feature = "debug")] |
| 213 |
pub use derive_more_impl::Debug; |
| 214 |
|
| 215 |
#[cfg(feature = "deref")] |
| 216 |
pub use derive_more_impl::Deref; |
| 217 |
|
| 218 |
#[cfg(feature = "deref_mut")] |
| 219 |
pub use derive_more_impl::DerefMut; |
| 220 |
|
| 221 |
#[cfg(feature = "display")] |
| 222 |
pub use derive_more_impl::{ |
| 223 |
Binary, Display, LowerExp, LowerHex, Octal, Pointer, UpperExp, UpperHex, |
| 224 |
}; |
| 225 |
|
| 226 |
#[cfg(feature = "error")] |
| 227 |
pub use derive_more_impl::Error; |
| 228 |
|
| 229 |
#[cfg(feature = "from")] |
| 230 |
pub use derive_more_impl::From; |
| 231 |
|
| 232 |
#[cfg(feature = "from_str")] |
| 233 |
pub use derive_more_impl::FromStr; |
| 234 |
|
| 235 |
#[cfg(feature = "index")] |
| 236 |
pub use derive_more_impl::Index; |
| 237 |
|
| 238 |
#[cfg(feature = "index_mut")] |
| 239 |
pub use derive_more_impl::IndexMut; |
| 240 |
|
| 241 |
#[cfg(feature = "into")] |
| 242 |
pub use derive_more_impl::Into; |
| 243 |
|
| 244 |
#[cfg(feature = "into_iterator")] |
| 245 |
pub use derive_more_impl::IntoIterator; |
| 246 |
|
| 247 |
#[cfg(feature = "is_variant")] |
| 248 |
pub use derive_more_impl::IsVariant; |
| 249 |
|
| 250 |
#[cfg(feature = "mul")] |
| 251 |
pub use derive_more_impl::{Div, Mul, Rem, Shl, Shr}; |
| 252 |
|
| 253 |
#[cfg(feature = "mul_assign")] |
| 254 |
pub use derive_more_impl::{DivAssign, MulAssign, RemAssign, ShlAssign, ShrAssign}; |
| 255 |
|
| 256 |
#[cfg(feature = "not")] |
| 257 |
pub use derive_more_impl::{Neg, Not}; |
| 258 |
|
| 259 |
#[cfg(feature = "sum")] |
| 260 |
pub use derive_more_impl::{Product, Sum}; |
| 261 |
|
| 262 |
#[cfg(feature = "try_into")] |
| 263 |
pub use derive_more_impl::TryInto; |
| 264 |
|
| 265 |
#[cfg(feature = "try_unwrap")] |
| 266 |
pub use derive_more_impl::TryUnwrap; |
| 267 |
|
| 268 |
#[cfg(feature = "unwrap")] |
| 269 |
pub use derive_more_impl::Unwrap; |
| 270 |
|
| 271 |
// Check if any feature is enabled |
| 272 |
#[cfg(not(any( |
| 273 |
feature = "full", |
| 274 |
feature = "add", |
| 275 |
feature = "add_assign", |
| 276 |
feature = "as_mut", |
| 277 |
feature = "as_ref", |
| 278 |
feature = "constructor", |
| 279 |
feature = "debug", |
| 280 |
feature = "deref", |
| 281 |
feature = "deref_mut", |
| 282 |
feature = "display", |
| 283 |
feature = "error", |
| 284 |
feature = "from", |
| 285 |
feature = "from_str", |
| 286 |
feature = "index", |
| 287 |
feature = "index_mut", |
| 288 |
feature = "into", |
| 289 |
feature = "into_iterator", |
| 290 |
feature = "is_variant", |
| 291 |
feature = "mul", |
| 292 |
feature = "mul_assign", |
| 293 |
feature = "not", |
| 294 |
feature = "sum", |
| 295 |
feature = "try_into", |
| 296 |
feature = "try_unwrap", |
| 297 |
feature = "unwrap", |
| 298 |
)))] |
| 299 |
compile_error!( |
| 300 |
"at least one derive feature must be enabled (or the \"full\" one enabling all the derives)" |
| 301 |
); |