Skip to main content

MapSchemaSource

Struct MapSchemaSource 

Source
pub struct MapSchemaSource { /* private fields */ }
Expand description

The schemas a host registered, as two maps.

What Config used to hold directly, behind the trait instead: schemas for built-in node types keyed by type, and schemas for tags keyed by name. builtin starts both at Markdoc’s own, which is where a host that adds a tag or replaces a node schema starts from; new starts both empty, for a host that supplies every schema itself.

The maps are reachable directly, because they are the whole content and hiding them would only add a method per operation. Fill one, then hand it to builtins::config_with, which builds the built-in schemas exactly once:

use std::sync::Arc;

use accent_proust::builtins;
use accent_proust::validate::{MapSchemaSource, Schema, SchemaKey};

let mut schemas = MapSchemaSource::builtin();
schemas.insert_tag("callout", Schema::new().render("aside"));

let config = builtins::config_with(Arc::new(schemas));
assert!(config.schemas.find(SchemaKey::Tag("callout")).is_some());
assert!(config.schemas.find(SchemaKey::Tag("if")).is_some());

Implementations§

Source§

impl MapSchemaSource

Source

pub fn new() -> MapSchemaSource

Nothing registered. Every lookup misses, which is what Config::new has always meant.

Source

pub fn builtin() -> MapSchemaSource

Markdoc’s own nodes and tags: what builtins::config starts from.

Source

pub fn insert_tag( &mut self, name: impl Into<String>, schema: Schema, ) -> &mut MapSchemaSource

Register a tag schema, replacing any under the same name.

Source

pub fn insert_node( &mut self, node_type: NodeType, schema: Schema, ) -> &mut MapSchemaSource

Register a node schema, replacing any for the same type.

Source

pub fn tags(&self) -> &IndexMap<String, Schema>

The tag schemas, by name.

Source

pub fn tags_mut(&mut self) -> &mut IndexMap<String, Schema>

The tag schemas, for in-place edit.

Source

pub fn nodes(&self) -> &IndexMap<NodeType, Schema>

The node schemas, by type.

Source

pub fn nodes_mut(&mut self) -> &mut IndexMap<NodeType, Schema>

The node schemas, for in-place edit.

Trait Implementations§

Source§

impl Clone for MapSchemaSource

Source§

fn clone(&self) -> MapSchemaSource

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 MapSchemaSource

Source§

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

The names registered, through the same two methods Config’s Debug reads, so the two renderings of one source cannot drift. A Schema carries hooks, which have no useful rendering, so the derived form is unavailable; the keys are what a reader chasing a tag-undefined wants anyway.

Source§

impl Default for MapSchemaSource

Source§

fn default() -> MapSchemaSource

Returns the “default value” for a type. Read more
Source§

impl SchemaSource for MapSchemaSource

Source§

fn find(&self, key: SchemaKey<'_>) -> Option<&Schema>

The schema for key, or None when this source does not define one. Read more
Source§

fn tag_names(&self) -> Option<Vec<&str>>

The tag names this source defines, when it can say. Read more
Source§

fn node_types(&self) -> Option<Vec<NodeType>>

The node types this source defines, when it can say. Read more

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> 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<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> 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> 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.