Controls metadata behavior for all zero kernel types.
| 186 | |
| 187 | /// Controls metadata behavior for all zero kernel types. |
| 188 | pub trait KernelMode: 'static + Clone + Debug + Send + Sync { |
| 189 | /// `true` iff this mode carries metadata. Enables compile-time |
| 190 | /// pruning: code paths gated by `if M::HAS_META { … }` are |
| 191 | /// monomorphized into the dead-branch-eliminated form for the Anon |
| 192 | /// implementation. Use this to guard metadata lookups so they don't |
| 193 | /// execute in Anon mode. |
| 194 | const HAS_META: bool; |
| 195 | |
| 196 | /// A metadata field: stores `T` in Meta mode, erased to `()` in Anon mode. |
| 197 | type MField<T: MetaHash + MetaDisplay + PartialEq + Clone + Debug + Hash + Send + Sync>: |
| 198 | MetaHash + MetaDisplay + PartialEq + Clone + Debug + Hash + Send + Sync; |
| 199 | |
| 200 | /// Wrap a value into a metadata field. In Anon mode, the value is discarded. |
| 201 | fn meta_field< |
| 202 | T: MetaHash + MetaDisplay + PartialEq + Clone + Debug + Hash + Send + Sync, |
| 203 | >( |
| 204 | val: T, |
| 205 | ) -> Self::MField<T>; |
| 206 | |
| 207 | /// Build a metadata field from a closure. Meta runs the closure to |
| 208 | /// produce the wrapped value; Anon discards the closure unevaluated |
| 209 | /// and returns `()`. The fallible counterpart is `meta_field_try`. |
| 210 | /// |
| 211 | /// Use this at metadata-extraction sites in mode-generic code: the |
| 212 | /// closure body — including arena walks, name resolution, and any |
| 213 | /// other work that only matters in Meta mode — is skipped entirely |
| 214 | /// when `M = Anon`, with no `Name::anon`-style placeholder |
| 215 | /// construction at the call site. |
| 216 | fn meta_field_with<T, F>(f: F) -> Self::MField<T> |
| 217 | where |
| 218 | T: MetaHash + MetaDisplay + PartialEq + Clone + Debug + Hash + Send + Sync, |
| 219 | F: FnOnce() -> T; |
| 220 | |
| 221 | /// Fallible variant of `meta_field_with`. Meta runs the closure (and |
| 222 | /// may return its `Err`); Anon discards the closure and returns |
| 223 | /// `Ok(())`. Use for sites where missing metadata is a Meta-mode |
| 224 | /// error but a no-op in Anon mode. |
| 225 | fn meta_field_try<T, F, E>(f: F) -> Result<Self::MField<T>, E> |
| 226 | where |
| 227 | T: MetaHash + MetaDisplay + PartialEq + Clone + Debug + Hash + Send + Sync, |
| 228 | F: FnOnce() -> Result<T, E>; |
| 229 | |
| 230 | /// Extract a name from a metadata field when running in Meta mode. |
| 231 | fn meta_name(field: &Self::MField<Name>) -> Option<Name>; |
| 232 | } |
| 233 | |
| 234 | /// Const-generic kernel mode. `META` controls metadata fields. |
| 235 | #[derive(Clone, Debug)] |
nothing calls this directly
no outgoing calls
no test coverage detected