Skip to main content

announce_std/
lib.rs

1//! Announced copies of std/core traits, so they can be passed to proc macros.
2//!
3//! `announce_std::iter::Iterator! { [announce_std::iter::Iterator!, cb!] }` passes
4//! a copy of `Iterator` to `cb!`. META holds `mock(::core::iter::Iterator)`:
5//! implement that real trait, not the copy. In the type namespace,
6//! `announce_std::iter::Iterator` is the real trait, so it works in bounds too.
7//!
8//! ```
9//! macro_rules! show {
10//!     (@announce_format "1" [$($l:tt)*] $($p:ident)? $(:: $s:ident)* ! => [mock($($m:tt)*)] { $($item:tt)* }) => {
11//!         const MOCKED: &str = stringify!($($m)*);
12//!     };
13//! }
14//! announce_std::iter::Iterator! { [announce_std::iter::Iterator!, show!] }
15//! assert_eq!(MOCKED, ":: core :: iter :: Iterator");
16//! // The type namespace holds the real trait:
17//! fn _f(_: &dyn announce_std::iter::Iterator<Item = u8>) {}
18//! ```
19//!
20//! **Old compilers.** `Debug`, `Hash`, `PartialEq`, `Eq`, `PartialOrd`, `Ord`,
21//! `Clone`, `Copy` and `Default` are also derive macro names. Before rustc 1.94,
22//! their type-namespace item is a blanket subtrait instead of the real trait. It
23//! works in bounds, but `impl announce_std::fmt::Debug for X` does not implement
24//! the real `Debug`. Write impls against the real path from `mock(..)`.
25//!
26//! **Not mocked.** `BuildHasher::hash_one` is stable only since Rust 1.71, and
27//! announce-std supports older compilers (MSRV 1.57), so a consumer that forwards
28//! it would break there. The `BuildHasher` mock has `build_hasher` only. To hash a
29//! value, use `Hash::hash`: `x.hash(&mut b.build_hasher())`, then `finish()` on
30//! the hasher.
31//!
32//! **Version gates.** Mocks of traits newer than the MSRV (1.57), or changed after
33//! it, are gated with `#[cfg(announce_std_rust_1_N)]`. `build.rs` sets that cfg on
34//! rustc 1.N and later, using `rustversion` attributes (`Termination` 1.61,
35//! `IntoFuture` 1.64, and the 1.80, 1.81 and 1.94 variants).
36
37#![cfg_attr(not(feature = "std"), no_std)]
38#![allow(clippy::all)]
39
40pub mod alloc;
41pub mod any;
42pub mod borrow;
43pub mod clone;
44pub mod cmp;
45pub mod convert;
46pub mod default;
47pub mod error;
48pub mod fmt;
49pub mod future;
50pub mod hash;
51#[cfg(feature = "std")]
52pub mod io;
53pub mod iter;
54pub mod marker;
55#[cfg(feature = "std")]
56pub mod net;
57pub mod ops;
58#[cfg(feature = "std")]
59pub mod process;
60#[cfg(feature = "std")]
61pub mod string;
62#[cfg(feature = "std")]
63pub mod task;