const_dispatch/
_lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#![doc = include_str!("../README.md")]
#![no_std]
#![forbid(unsafe_code)]
#![allow(uncommon_codepoints)] // `fn const_dispatchǃ` below
#![warn(missing_docs)]
#![cfg_attr(feature = "better-docs",
    feature(doc_cfg),
)]

pub mod prelude {
    //! The crate's prelude, designed to be `*`-blob imported.
    #[doc(no_inline)]
    pub use crate::{
        primitive::*,
        const_dispatch,
        ConstDispatch,
    };
}

pub mod primitive;

/// Derives/`impl`ements [`ConstDispatch`][trait@ConstDispatch] for the given type.
///
/// The input must be a simple `enum`: that is, an `enum` whose variants have no payloads
/// (often also called a "C `enum`").
#[doc(inline)] // TODO
pub use ::const_dispatch_proc_macros::ConstDispatch;

/// Marker trait for types which may be fed to [`const_dispatch!`].
///
/// It is not to be implemented manually: only through its eponymous
/// <code>#\[[derive]\([ConstDispatch][macro@ConstDispatch]\)\]</code>.
///
/// [derive]: [macro@derive]
#[diagnostic::on_unimplemented(
    note = "the `enum` definition is missing a `#[derive(ConstDispatch)]`",
)]
pub trait ConstDispatch : ඞ::MacroDerived {}

mod const_dispatch_macro;

mod derive;

// macro internals
#[doc(hidden)] /** Not part of the public API */ pub
mod ඞ {
    #![allow(missing_docs)]
    pub use ::core;

    pub use crate::ඞderive_ConstDispatch as derive_ConstDispatch;

    pub use ::const_dispatch_proc_macros::ඞexterminate as exterminate;

    pub use ::paste::paste;

    pub trait MacroDerived {}
    impl<T : ?Sized> ConstDispatch for T where Self : MacroDerived {}

    /* See the NOTE: above as to why we are not using this anymore. */
    // #[doc(hidden)] /** Not part of the public API */ #[macro_export]
    // macro_rules! ඞfallback_const_dispatch {(
    //     $scrutinee:expr, $($rest:tt)*
    // ) => (
    //     $crate::ඞ::const_dispatchǃ($scrutinee, ())
    // )}
    // #[doc(inline)]
    // pub use ඞfallback_const_dispatch as fallback_const_dispatch;

    use Sized as FnOnceConst;
    use crate::ConstDispatch;

    pub fn
    /* macro */ const_dispatchǃ(_scrutinee: impl ConstDispatch, _dispatch: impl FnOnceConst) -> ! {
        unimplemented!()
    }
}

#[doc = include_str!("compile_fail_tests.md")]
mod _compile_fail_tests {}