pub struct TraceryGrammar { /* private fields */ }
Expand description

This is a grammar that handles rules provided in a tracery syntax. See - https://github.com/galaxykate/tracery for more info on Tracery.

Implementations§

source§

impl TraceryGrammar

source

pub fn empty() -> Self

This provides an empty tracery grammar. Mostly used for handling stateless generators.

source

pub fn new<T: Clone + Into<String>>( rules: &[(T, &[T])], starting_point: Option<T> ) -> Self

This provides a new tracery grammar. You provide a set of rules as (Key, &[Values]) and optionally a starting point. If no starting point is provided, we fall back on “origin”

Trait Implementations§

source§

impl Clone for TraceryGrammar

source§

fn clone(&self) -> TraceryGrammar

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Component for TraceryGrammarwhere Self: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either [TableStorage] or [SparseStorage].
source§

impl Debug for TraceryGrammar

source§

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

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

impl<'de> Deserialize<'de> for TraceryGrammar

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Generator<String, String, String, TraceryGrammar> for StringGenerator

source§

fn generate<R: GrammarRandomNumberGenerator>( grammar: &TraceryGrammar, rng: &mut R ) -> Option<String>

This function generates a new value of StreamType, starting from the grammar’s default rule
source§

fn generate_at<R: GrammarRandomNumberGenerator>( key: &String, grammar: &TraceryGrammar, rng: &mut R ) -> Option<String>

This function generates a new value of StreamType, starting from a provided rule key
source§

fn expand_from<R: GrammarRandomNumberGenerator>( initial: &String, grammar: &TraceryGrammar, rng: &mut R ) -> String

This function generates a new value of StreamType, starting by processing an initial input of StreamType
source§

impl Grammar<String, String, String> for TraceryGrammar

source§

fn rule_keys(&self) -> &Vec<String>

Gets a Vec of all the possible rule keys - can be used to see if any match
source§

fn has_rule(&self, rule: &String) -> bool

Checks if a given rule key is available
source§

fn default_starting_point(&self) -> &String

Gets the default starting key - used if no other key is set
source§

fn get_rule_options(&self, rule: &String) -> Option<&Vec<String>>

Gets all the possible expansions from a rule key
source§

fn check_token_stream( &self, stream: &String ) -> (bool, Vec<Replacable<String, String>>)

Parses a token stream and determines a) whether there are any tokens to replace and b) if so, which The bool is true if there are no more tokens that need replacing
source§

fn rule_to_default_result(&self, rule: &String) -> String

Converts a rule key to a default result, in case no matching rule is found in the grammar.
source§

fn processing_direction(&self) -> GrammarProcessingDirection

determines if the grammar should be processed breadth-first or depth-first
source§

fn result_to_stream(&self, result: &[String]) -> String

Converts a group of result types to a stream type
source§

fn set_additional_rules(&mut self, rule: String, values: &[String])

This is a function for setting a new rule. The expectation is that it overrides the original.
source§

fn stream_to_result(&self, stream: &String) -> Vec<String>

Converts a stream to a vec of result type
source§

fn select_from_rule<R: GrammarRandomNumberGenerator>( &self, rule: &RuleKeyType, rng: &mut R ) -> Option<&ResultType>

Selects an element from a rule’s options. provides a default implementation in case no weighting is ncessessary. The RNG function should accept the total number of options, and return a single id (a number less than the total). If it is larger, we will use the last element.
source§

fn copy_and_replace_rules(&mut self, other: &Self)

This is used to clone all the roles from another grammar into this one. This is used by stateful generators to update their state.
source§

fn max_depth(&self) -> usize

Provides the maximum depth (number of iterations) allowed for the generator. It will always quit early if it stabilizes, but otherwise it will conclude when it reaches the provided depth.
source§

fn process_stream<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, rng: &mut R, temporary_grammar: &mut Self ) -> StreamType

Takes a token stream, checks it for replacements, and then applies them by using select from rule. It returns a bool indicating whether it had to make any replacements this round, and a vec of the results.
source§

fn breadth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType

Processes a stream breadth first, regardless of the settings of the grammar
source§

fn depth_first_processing<R: GrammarRandomNumberGenerator>( &self, stream: &StreamType, temporary_grammar: &mut Self, rng: &mut R ) -> StreamType

Processes a stream depth first, regardless of the settings of the grammar
source§

impl Serialize for TraceryGrammar

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StatefulGenerator<String, String, String, TraceryGrammar> for StatefulStringGenerator

source§

fn generate<R: GrammarRandomNumberGenerator>( &mut self, rng: &mut R ) -> Option<String>

This function generates a new value of StreamType, starting from the grammar’s default rule
source§

fn generate_at<R: GrammarRandomNumberGenerator>( &mut self, key: &String, rng: &mut R ) -> Option<String>

This function generates a new value of StreamType, starting from a provided rule key
source§

fn expand_from<R: GrammarRandomNumberGenerator>( &mut self, initial: &String, rng: &mut R ) -> String

This function generates a new value of StreamType, starting by processing an initial input of StreamType
source§

fn set_grammar(&mut self, grammar: &TraceryGrammar)

This sets the used grammar
source§

fn get_grammar(&self) -> &TraceryGrammar

This gets an immutable reference to the grammar
source§

fn get_grammar_mut(&mut self) -> &mut TraceryGrammar

This gets a mutable reference to the grammar
source§

impl TypePath for TraceryGrammar

source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
source§

impl TypeUuid for TraceryGrammar

source§

impl VisitAssetDependencies for TraceryGrammar

source§

fn visit_dependencies(&self, _visit: &mut impl FnMut(UntypedAssetId))

source§

impl Asset for TraceryGrammar

source§

impl Resource for TraceryGrammarwhere Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<A> AssetContainer for Awhere A: Asset,

§

fn insert(self: Box<A, Global>, id: UntypedAssetId, world: &mut World)

§

fn asset_type_name(&self) -> &'static str

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<C> Bundle for Cwhere C: Component,

§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )

§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> Cwhere F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a, Aligned>,

§

impl<T> Downcast for Twhere T: Any,

§

fn into_any(self: Box<T, Global>) -> Box<dyn Any, Global>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T, Global>) -> Rc<dyn Any, Global>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for Twhere T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T, Global>) -> Arc<dyn Any + Sync + Send, Global>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<C> DynamicBundle for Cwhere C: Component,

§

fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_, Aligned>) )

§

impl<T> DynamicTypePath for Twhere T: TypePath,

§

fn reflect_type_path(&self) -> &str

See [TypePath::type_path].
§

fn reflect_short_type_path(&self) -> &str

See [TypePath::short_type_path].
§

fn reflect_type_ident(&self) -> Option<&str>

See [TypePath::type_ident].
§

fn reflect_crate_name(&self) -> Option<&str>

See [TypePath::crate_name].
§

fn reflect_module_path(&self) -> Option<&str>

See [TypePath::module_path].
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Serialize for Twhere T: Serialize + ?Sized,

source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>

source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

impl<T> TypeData for Twhere T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData, Global>

§

impl<T> TypeUuidDynamic for Twhere T: TypeUuid,

§

fn type_uuid(&self) -> Uuid

Returns the UUID associated with this value’s type.

§

fn type_name(&self) -> &'static str

Returns the type name of this value’s type.

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

§

impl<T> Settings for Twhere T: 'static + Send + Sync,