Skip to main content

NativeImplication

Struct NativeImplication 

Source
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 aspect A must write the element natively too. The aspect is given by its trait-object type, exactly as it is attached with FeatureBuilder::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: ElementName

The element a backend must write natively when the implication applies to it. Some feature of the same registry must declare it.

§kind: NativeImplicationKind

When the implication applies to a backend.

§docs: String

Documentation prose: why a backend must write the element natively.

Implementations§

Source§

impl NativeImplication

Source

pub fn always(element: impl Into<ElementName>) -> NativeImplication

An implication that requires every backend to write element natively, with no documentation.

Source

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.

Source

pub fn docs(self, docs: impl Into<String>) -> NativeImplication

Sets the documentation prose. Returns self, for chaining.

Source

pub fn applies_to(&self, element: &ElementSpec) -> bool

Whether a backend whose native set holds element must satisfy this implication: always, for the Always form; for the Aspect form, when element carries the aspect.

Trait Implementations§

Source§

impl Clone for NativeImplication

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NativeImplication

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for NativeImplication

Source§

impl PartialEq for NativeImplication

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NativeImplication

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.