pub struct NativeImplication {
pub must_claim: ElementName,
pub kind: NativeImplicationKind,
pub docs: String,
}Expand description
A native-set implication: a requirement on what a backend’s native set must contain, checked against every backend when the registry is built.
A backend’s native set is the list of elements its emit stage writes
directly (BackendDef::native). Lowering rules turn every other element
into those elements, and plan construction follows the rules’ produces
declarations to check that the backend can write everything a document may
contain. Two elements are outside that check, because the lowering driver
creates their nodes itself, with no rule declaring them:
flm.pres.deco-mark, the node left where a decoration was moved out of a
content run into an attached slot (see decorations, roles and
kinds), and
flm.pres.unsupported, the stand-in node for an element accepted as
unrenderable or for an element whose rule failed. A backend must still
write these elements natively. Without a declared requirement, a backend
that omits one would fail only at lowering, with a missing-rule error, at
the first document that needs the element. A native-set implication states
the requirement as data: the registry build checks it and fails with
BuildError::NativeSetIncomplete, which identifies the backend, the
element it must also write natively and, where there is one, the native
element that made the implication apply.
An implication takes one of two forms, given by its
NativeImplicationKind:
always: every backend of the registry must write the element natively.aspect::<A>: a backend whose native set holds any element carrying the aspectAmust write the element natively too. The aspect is given by its trait-object type, exactly as it is attached withFeatureBuilder::attach, so the check compares the aspect’s identity, not element names: every element that carries the aspect counts, whichever feature registered it, and the check runs after the aspects that features attach to other features’ elements have been merged in.
The standard feature lowering declares the two
implications described above. A feature whose lowering driver, emitter or
rules create nodes of an element without declaring it in a rule’s
produces should declare an implication for it. Register one with
FeatureBuilder::native_implication;
FlmRegistry::native_implications
lists those a registry holds. An implication decides whether a registry
builds and never what a run produces, so it is not an input of the registry
digest.
§Examples
use flm_core::core::registry::{NativeImplication, NativeImplicationKind};
use flm_core::stdlib::backends::pres::{self, Decoration};
let marker = NativeImplication::aspect::<dyn Decoration>(pres::DECO_MARK)
.docs("a backend claiming a decoration must claim the marker left in its place");
let stand_in = NativeImplication::always(pres::UNSUPPORTED);
assert_eq!(stand_in.kind, NativeImplicationKind::Always);
assert!(matches!(marker.kind, NativeImplicationKind::Aspect { .. }));
assert_eq!(marker.must_claim, pres::DECO_MARK);Fields§
§must_claim: ElementNameThe element a backend must write natively when the implication applies to it. Some feature of the same registry must declare it.
kind: NativeImplicationKindWhen the implication applies to a backend.
docs: StringDocumentation prose: why a backend must write the element natively.
Implementations§
Source§impl NativeImplication
impl NativeImplication
Sourcepub fn always(element: impl Into<ElementName>) -> NativeImplication
pub fn always(element: impl Into<ElementName>) -> NativeImplication
An implication that requires every backend to write element
natively, with no documentation.
Sourcepub fn aspect<A: ?Sized + Any + Send + Sync>(
element: impl Into<ElementName>,
) -> NativeImplication
pub fn aspect<A: ?Sized + Any + Send + Sync>( element: impl Into<ElementName>, ) -> NativeImplication
An implication that requires a backend whose native set holds any
element carrying the aspect A to write element natively as well;
with no documentation.
Write A as the aspect’s trait-object type, as in
NativeImplication::aspect::<dyn Decoration>(pres::DECO_MARK), with
the same bounds as
FeatureBuilder::attach. A concrete
type fails to compile: an aspect is attached under its trait-object
type, so an implication keyed by any other type would match no element
and never apply.
Sourcepub fn docs(self, docs: impl Into<String>) -> NativeImplication
pub fn docs(self, docs: impl Into<String>) -> NativeImplication
Sets the documentation prose. Returns self, for chaining.
Sourcepub fn applies_to(&self, element: &ElementSpec) -> bool
pub fn applies_to(&self, element: &ElementSpec) -> bool
Trait Implementations§
Source§impl Clone for NativeImplication
impl Clone for NativeImplication
Source§impl Debug for NativeImplication
impl Debug for NativeImplication
impl Eq for NativeImplication
Source§impl PartialEq for NativeImplication
impl PartialEq for NativeImplication
impl StructuralPartialEq for NativeImplication
Auto Trait Implementations§
impl Forget for NativeImplication
impl Freeze for NativeImplication
impl Move for NativeImplication
impl RefUnwindSafe for NativeImplication
impl Send for NativeImplication
impl Sync for NativeImplication
impl Unpin for NativeImplication
impl UnsafeUnpin for NativeImplicationwhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const (): UnsafeUnpin,
&'static str: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
impl UnwindSafe for NativeImplicationwhere
Arc<str>: UnwindSafe,
*const (): UnwindSafe,
&'static str: UnwindSafe,
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more