Skip to main content

DirectiveOptions

Struct DirectiveOptions 

Source
pub struct DirectiveOptions {
    pub name: String,
    pub open: String,
    pub close: Option<String>,
    pub action: DirectiveAction,
    pub rules: Option<RulesOption>,
    pub custom: Option<CustomFn>,
}
Expand description

Configuration for one directive.

Built with DirectiveOptions::new plus the with_* methods, then handed to apply or plugin.

Fields§

§name: String

The directive name, used as the rule name and token-name suffix. It must be non-empty and contain no whitespace — registration rejects anything else, because the serialized grammar could not name the token.

§open: String

The character sequence that starts the directive. It must be unique — re-registering an existing fixed token is an error.

§close: Option<String>

The optional character sequence that ends the directive. Without one the directive consumes a single value after the open token.

§action: DirectiveAction

How the parsed body is transformed.

§rules: Option<RulesOption>

Which existing grammar rules are modified. None selects the defaults (open val, close list,elem,map,pair); Some(value) is a complete override, so Some(RulesOption::new()) modifies no rules.

TypeScript deep-merges its defaults into whatever rules is passed, so a partial rules there keeps the default of the direction it omits. Rust, like Go, cannot express that merge over a typed option and treats any Some as complete. This is an intentional divergence — see docs/reference.md.

§custom: Option<CustomFn>

Extra parser customization once the directive rule exists.

Implementations§

Source§

impl DirectiveOptions

Source

pub fn new(name: impl Into<String>, open: impl Into<String>) -> Self

A directive named name, opened by the token source open.

Source

pub fn with_close(self, close: impl Into<String>) -> Self

Give the directive a close token.

Source

pub fn with_action( self, action: impl Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Send + Sync + 'static, ) -> Self

Set a classic action: write the result to rule.node.

Source

pub fn with_token_action( self, action: impl Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Send + Sync + 'static, ) -> Self

Set an action that may return a token for the close hook to forward.

Source

pub fn with_action_path(self, path: impl Into<String>) -> Self

Set a dotted-path action resolved against the plugin options when the directive fires. See DirectiveAction::Path.

Source

pub fn with_rules(self, rules: RulesOption) -> Self

Override which host rules are modified.

Source

pub fn with_custom( self, custom: impl Fn(&mut Tabnas, &DirectiveConfig) + Send + Sync + 'static, ) -> Self

Run custom once the directive rule exists.

Trait Implementations§

Source§

impl Clone for DirectiveOptions

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 DirectiveOptions

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for DirectiveOptions

§

impl !UnwindSafe for DirectiveOptions

§

impl Forget for DirectiveOptions

§

impl Freeze for DirectiveOptions
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send>>: Freeze, *const ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send>>: Freeze, *const LeafNode<String, RuleMod> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, RuleMod)>>: Freeze, *const ArcInner<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send>>: Freeze,

§

impl Move for DirectiveOptions

§

impl Send for DirectiveOptions
where RawVecInner: Send, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send>: Send, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send>: Send, NodeRef<Owned, String, RuleMod, LeafOrInternal>: Send, BoxRaw<(String, RuleMod)>: Send, Arc<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send>: Send,

§

impl Sync for DirectiveOptions
where RawVecInner: Sync, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send>: Sync, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send>: Sync, NodeRef<Owned, String, RuleMod, LeafOrInternal>: Sync, BoxRaw<(String, RuleMod)>: Sync, Arc<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send>: Sync,

§

impl Unpin for DirectiveOptions
where *const u8 is !null: Unpin, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send>: Unpin, Arc<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send>: Unpin, *const LeafNode<String, RuleMod> is !null: Unpin, Box<(String, RuleMod)>: Unpin, Arc<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send>: Unpin,

§

impl UnsafeUnpin for DirectiveOptions
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<(), ActionError> + Sync + Send>>: UnsafeUnpin, *const ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&mut Rule, &mut Context) -> Result<Option<Token>, ActionError> + Sync + Send>>: UnsafeUnpin, *const LeafNode<String, RuleMod> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, RuleMod)>>: UnsafeUnpin, *const ArcInner<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&mut Tabnas, &DirectiveConfig) + Sync + Send>>: UnsafeUnpin,

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.