const_dispatch/
_lib.rs

1//! [`const_dispatch!`]: const_dispatch!
2#![doc = include_str!("../README.md")]
3#![no_std]
4#![forbid(unsafe_code)]
5#![allow(uncommon_codepoints)] // `fn const_dispatchǃ` below
6#![warn(missing_docs)]
7#![cfg_attr(feature = "better-docs",
8    feature(doc_cfg),
9)]
10
11pub mod prelude {
12    //! The crate's prelude, designed to be `*`-blob imported.
13    #[doc(no_inline)]
14    pub use crate::{
15        primitive::*,
16        const_dispatch,
17        ConstDispatch,
18    };
19}
20
21pub mod primitive;
22
23/// Derives/`impl`ements [`ConstDispatch`][trait@ConstDispatch] for the given type.
24///
25/// The input must be a simple `enum`: that is, an `enum` whose variants have no payloads
26/// (often also called a "C `enum`").
27#[doc(inline)] // TODO
28pub use ::const_dispatch_proc_macros::ConstDispatch;
29
30/// Marker trait for types which may be fed to [`const_dispatch!`].
31///
32/// It is not to be implemented manually: only through its eponymous
33/// <code>#\[[derive]\([ConstDispatch][macro@ConstDispatch]\)\]</code>.
34///
35/// [derive]: [macro@derive]
36#[diagnostic::on_unimplemented(
37    note = "the `enum` definition is missing a `#[derive(ConstDispatch)]`",
38)]
39pub trait ConstDispatch : ඞ::MacroDerived {}
40
41mod const_dispatch_macro;
42
43mod derive;
44
45// macro internals
46#[doc(hidden)] /** Not part of the public API */ pub
47mod ඞ {
48    #![allow(missing_docs)]
49    pub use ::core;
50
51    pub use crate::ඞderive_ConstDispatch as derive_ConstDispatch;
52
53    pub use ::const_dispatch_proc_macros::ඞexterminate as exterminate;
54    pub use ::const_dispatch_proc_macros::ඞtry_hide as try_hide;
55
56    pub use ::paste::paste;
57    pub use ::never_say_never::Never;
58
59    pub trait MacroDerived {}
60    impl<T : ?Sized> ConstDispatch for T where Self : MacroDerived {}
61
62    /* See the NOTE: above as to why we are not using this anymore. */
63    // #[doc(hidden)] /** Not part of the public API */ #[macro_export]
64    // macro_rules! ඞfallback_const_dispatch {(
65    //     $scrutinee:expr, $($rest:tt)*
66    // ) => (
67    //     $crate::ඞ::const_dispatchǃ($scrutinee, ())
68    // )}
69    // #[doc(inline)]
70    // pub use ඞfallback_const_dispatch as fallback_const_dispatch;
71
72    use Sized as FnOnceConst;
73    use crate::ConstDispatch;
74
75    pub fn
76    /* macro */ const_dispatchǃ(_scrutinee: impl ConstDispatch, _dispatch: impl FnOnceConst) -> ! {
77        unimplemented!()
78    }
79}
80
81#[doc = include_str!("compile_fail_tests.md")]
82mod _compile_fail_tests {}