pub struct Validator<'a> {
block: &'a Block,
data: &'a Everything,
known_fields: Vec<&'a str>,
accepted_tokens: bool,
accepted_blocks: bool,
accepted_block_fields: bool,
accepted_value_fields: bool,
case_sensitive: bool,
allow_questionmark_equals: bool,
max_severity: Severity,
}
Expand description
A validator for one Block
.
The intended usage is that you wrap the Block
in a validator, then call validation functions on it
until you’ve validated all the possible legitimate contents of the Block
, and then the Validator
will warn the user about anything left over when it goes out of scope. This way you don’t have to worry
about checking for unknown fields yourself.
The validator is mostly for checking “fields” (key = value
and key = { block }
items in the block),
but it can validate loose blocks and loose values and comparisons as well.
Fields§
§block: &'a Block
The block being validated
data: &'a Everything
A link to all the loaded and processed CK3 and mod files
known_fields: Vec<&'a str>
Fields that have been requested so far
accepted_tokens: bool
Whether loose tokens are expected
accepted_blocks: bool
Whether subblocks are expected
accepted_block_fields: bool
Whether unknown block fields are expected
accepted_value_fields: bool
Whether unknown value fields are expected
case_sensitive: bool
Whether key comparisons should be done case-sensitively
allow_questionmark_equals: bool
Whether this block can have ?= operators
max_severity: Severity
Maximum severity of problems reported by this Validator
. Defaults to Error
.
This is intended to be set lower by validators for less-important items.
As an exception, Fatal
severity reports will still always be logged as Fatal
.
TODO: pass this down to all the helper functions
Implementations§
Source§impl<'a> Validator<'a>
impl<'a> Validator<'a>
Sourcepub fn new(block: &'a Block, data: &'a Everything) -> Self
pub fn new(block: &'a Block, data: &'a Everything) -> Self
Construct a new Validator
for a Block
. The data
reference is there to help out some of the convenience
functions, and also to pass along to closures so that you can easily pass independent functions as the closures.
Sourcepub fn set_case_sensitive(&mut self, cs: bool)
pub fn set_case_sensitive(&mut self, cs: bool)
Control whether the fields in this Block
will be matched case-sensitively or not.
Whether this should be on or off depends on what the game engine allows, which is not always known.
Sourcepub fn set_allow_questionmark_equals(&mut self, allow_questionmark_equals: bool)
pub fn set_allow_questionmark_equals(&mut self, allow_questionmark_equals: bool)
Whether this block can contain ?=
as well as =
for assignments and definitions.
Blocks that allow ?=
are mostly specialized ones such as triggers and effects.
pub fn set_max_severity(&mut self, max_severity: Severity)
Sourcepub fn req_field(&mut self, name: &str) -> bool
pub fn req_field(&mut self, name: &str) -> bool
Require field name
to be present in the block, and warn if it isn’t there.
Returns true iff the field is present.
Sourcepub fn req_field_one_of(&mut self, names: &[&str]) -> bool
pub fn req_field_one_of(&mut self, names: &[&str]) -> bool
Require exactly one of the fields in names
to be present in the block,
and warn if they are missing or there is more than one.
Returns true iff it found exactly one.
Sourcepub fn req_field_warn(&mut self, name: &str) -> bool
pub fn req_field_warn(&mut self, name: &str) -> bool
Require field name
to be present in the block, and warn if it isn’t there.
Returns true iff the field is present. Warns at a lower severity than req_field
.
Sourcepub fn req_field_fatal(&mut self, name: &str) -> bool
pub fn req_field_fatal(&mut self, name: &str) -> bool
Require field name
to be present in the block, and warn if it isn’t there.
Returns true iff the field is present. Warns at Severity::Fatal
level.
Sourcepub fn ban_field<F, S>(&mut self, name: &str, only_for: F)
pub fn ban_field<F, S>(&mut self, name: &str, only_for: F)
Require field name
to not be in the block, and warn if it is found.
The warning will include the output from the only_for
closure,
which describes where the field is expected.
TODO: make lower-severity versions of this function.
Sourcepub fn replaced_field(&mut self, name: &str, replaced_by: &str)
pub fn replaced_field(&mut self, name: &str, replaced_by: &str)
Require field name
to not be in the block. If it is found, warn that it has been replaced by replaced_by
.
This is used to adapt to and warn about changes in the game engine.
fn check_key(&mut self, name: &str) -> bool
fn field_check<F>(&mut self, name: &str, f: F) -> bool
fn multi_field_check<F>(&mut self, name: &str, f: F) -> bool
Sourcepub fn field(&mut self, name: &str) -> bool
pub fn field(&mut self, name: &str) -> bool
Expect field name
, if present, to be either an assignment (= value
) or a definition (= { block }
).
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn multi_field(&mut self, name: &str) -> bool
pub fn multi_field(&mut self, name: &str) -> bool
Just like Validator::field
, but expects any number of name
fields in the block.
Sourcepub fn field_any_cmp(&mut self, name: &str) -> Option<&BV>
pub fn field_any_cmp(&mut self, name: &str) -> Option<&BV>
Expect field name
, if present, to be… present.
Expect no more than one name
field in the block.
Returns the field’s BV
(block or value) if the field is present.
TODO: replace this with a field_validated
variant.
Sourcepub fn field_value(&mut self, name: &str) -> Option<&Token>
pub fn field_value(&mut self, name: &str) -> Option<&Token>
Expect field name
, if present, to be an assignment (name = value
).
Expect no more than one name
field in the block.
Returns the field’s value if the field is present.
Sourcepub fn field_validated_value<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated_value<F>(&mut self, name: &str, f: F) -> bool
Expect field name
, if present, to be an assignment (name = value
).
Expect no more than one name
field in the block.
Runs the validation closure f(key, vd)
for every matching field.
Returns true iff the field is present.
Sourcepub fn multi_field_validated_value<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated_value<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_value
, but expect any number of name
fields in the block.
Sourcepub fn field_item(&mut self, name: &str, itype: Item) -> bool
pub fn field_item(&mut self, name: &str, itype: Item) -> bool
Expect field name
, if present, to be set to the key of an itype
item the game database.
The item is looked up and must exist.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_action(&mut self, name: &str, sc: &ScopeContext) -> bool
pub fn field_action(&mut self, name: &str, sc: &ScopeContext) -> bool
Expect field name
, if present, to be set to the key of an on_action
.
The action is looked up and must exist.
If it would be useful, validate the action with the given ScopeContext
.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_event(&mut self, name: &str, sc: &mut ScopeContext) -> bool
pub fn field_event(&mut self, name: &str, sc: &mut ScopeContext) -> bool
Expect field name
, if present, to be set to an event id.
The event is looked up and must exist.
If it would be useful, validate the event with the given ScopeContext
.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_item_or_empty(&mut self, name: &str, itype: Item) -> bool
pub fn field_item_or_empty(&mut self, name: &str, itype: Item) -> bool
Expect field name
, if present, to be set to the key of an itype
item the game database,
or be the empty string.
The item is looked up and must exist.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_localization(&mut self, name: &str, sc: &mut ScopeContext) -> bool
pub fn field_localization(&mut self, name: &str, sc: &mut ScopeContext) -> bool
Expect field name
, if present, to be a localization key.
The key is looked up and must exist.
The key’s localization entry is validated using the given ScopeContext
.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_target(
&mut self,
name: &str,
sc: &mut ScopeContext,
outscopes: Scopes,
) -> bool
pub fn field_target( &mut self, name: &str, sc: &mut ScopeContext, outscopes: Scopes, ) -> bool
Expect field name
, if present, to be an assignment where the value evaluates to a scope type in outscopes
.
The value is evaluated in the scope context sc
, so for example if the value does scope:actor
but there is
no named scope “actor” in the scope context, then a warning is emitted.
Also emits a warning if the value is simply “this
”, because that is almost never correct.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn multi_field_target(
&mut self,
name: &str,
sc: &mut ScopeContext,
outscopes: Scopes,
) -> bool
pub fn multi_field_target( &mut self, name: &str, sc: &mut ScopeContext, outscopes: Scopes, ) -> bool
Returns true iff the field is present.
Just like Validator::field_target
, but allows multiple fields.
Sourcepub fn field_target_ok_this(
&mut self,
name: &str,
sc: &mut ScopeContext,
outscopes: Scopes,
) -> bool
pub fn field_target_ok_this( &mut self, name: &str, sc: &mut ScopeContext, outscopes: Scopes, ) -> bool
Just like Validator::field_target
, but allows the value to be simply “this
”.
It is expected to be used judiciously in cases where “this
” can be correct.
Sourcepub fn field_item_or_target(
&mut self,
name: &str,
sc: &mut ScopeContext,
itype: Item,
outscopes: Scopes,
) -> bool
pub fn field_item_or_target( &mut self, name: &str, sc: &mut ScopeContext, itype: Item, outscopes: Scopes, ) -> bool
This is a combination of Validator::field_item
and Validator::field_target
. If the field is present
and is not a known itype
item, then it is evaluated as a target.
Returns true iff the field is present.
Sourcepub fn field_item_or_target_ok_this(
&mut self,
name: &str,
sc: &mut ScopeContext,
itype: Item,
outscopes: Scopes,
) -> bool
pub fn field_item_or_target_ok_this( &mut self, name: &str, sc: &mut ScopeContext, itype: Item, outscopes: Scopes, ) -> bool
This is a combination of Validator::field_item
and Validator::field_target_ok_this
.
If the field is present and is not a known itype
item, then it is evaluated as a target.
Returns true iff the field is present.
Sourcepub fn field_block(&mut self, name: &str) -> bool
pub fn field_block(&mut self, name: &str) -> bool
Expect field name
, if present, to be a definition name = { block }
.
Expect no more than one name
field.
No other validation is done.
Returns true iff the field is present.
Sourcepub fn field_bool(&mut self, name: &str) -> bool
pub fn field_bool(&mut self, name: &str) -> bool
Expect field name
, if present, to be name = yes
or name = no
.
Expect no more than one name
field.
Returns true iff the field is present.
Sourcepub fn field_integer(&mut self, name: &str) -> bool
pub fn field_integer(&mut self, name: &str) -> bool
Expect field name
, if present, to be set to an integer.
Expect no more than one name
field.
Returns true iff the field is present.
Sourcepub fn field_integer_range<R: RangeBounds<i64>>(&mut self, name: &str, range: R)
pub fn field_integer_range<R: RangeBounds<i64>>(&mut self, name: &str, range: R)
Expect field name
, if present, to be set to an integer within the range
provided.
Expect no more than one name
field.
Returns true iff the field is present.
Sourcepub fn field_numeric(&mut self, name: &str) -> bool
pub fn field_numeric(&mut self, name: &str) -> bool
Expect field name
, if present, to be set to a number with up to 5 decimals.
(5 decimals is the limit accepted by the game engine in most contexts).
Expect no more than one name
field.
Returns true iff the field is present.
Sourcepub fn field_precise_numeric(&mut self, name: &str) -> bool
pub fn field_precise_numeric(&mut self, name: &str) -> bool
Expect field name
, if present, to be set to a number with any number of decimals.
Expect no more than one name
field.
Returns true iff the field is present.
pub fn field_numeric_range_internal<R: RangeBounds<f64>>( &mut self, name: &str, range: R, precise: bool, )
Sourcepub fn field_numeric_range<R: RangeBounds<f64>>(&mut self, name: &str, range: R)
pub fn field_numeric_range<R: RangeBounds<f64>>(&mut self, name: &str, range: R)
Expect field name
, if present, to be set to a number within the range
provided.
Accept at most 5 decimals. (5 decimals is the limit accepted by the game engine in most contexts).
Expect no more than one name
field.
Sourcepub fn field_precise_numeric_range<R: RangeBounds<f64>>(
&mut self,
name: &str,
range: R,
)
pub fn field_precise_numeric_range<R: RangeBounds<f64>>( &mut self, name: &str, range: R, )
Expect field name
, if present, to be set to a number within the range
provided.
Expect no more than one name
field.
Sourcepub fn field_date(&mut self, name: &str) -> bool
pub fn field_date(&mut self, name: &str) -> bool
Expect field name
, if present, to be set to a date.
The format of dates is very flexible, from a single number (the year), to a year.month or year.month.day.
No checking is done on the validity of the date as a date (so January 42nd is okay).
Expect no more than one name
field.
Returns true iff the field is present.
Sourcepub fn field_trigger_full<'b, T>(
&mut self,
name: &str,
fsc: T,
tooltipped: Tooltipped,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
pub fn field_trigger_full<'b, T>(
&mut self,
name: &str,
fsc: T,
tooltipped: Tooltipped,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
Expect field name
, if present, to be set to a trigger block.
The scope context may be a full ScopeContext
, a rooted Scopes
or a closure that builds
one from the field key token.
Sourcepub fn field_effect_full<'b, T>(
&mut self,
name: &str,
fsc: T,
tooltipped: Tooltipped,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
pub fn field_effect_full<'b, T>(
&mut self,
name: &str,
fsc: T,
tooltipped: Tooltipped,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
Expect field name
, if present, to be set to an effect block.
The scope context may be a full ScopeContext
, a rooted Scopes
or a closure that builds
one from the field key token.
Sourcepub fn field_script_value_full<'b, T>(
&mut self,
name: &str,
fsc: T,
breakdown: bool,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
pub fn field_script_value_full<'b, T>(
&mut self,
name: &str,
fsc: T,
breakdown: bool,
) -> boolwhere
T: Into<FieldScopeContext<'b>>,
Epexect field name
, if present, to be set to a script value.
The scope context may be a full ScopeContext
, a rooted Scopes
or a closure that builds
one from the field key token.
If breakdown
is true, it does not warn if it is an inline script value and the desc
fields in it do not contain valid localizations. This is generally used for script values
that will never be shown to the user except in debugging contexts, such as ai_will_do
.
Sourcepub fn field_script_value(&mut self, name: &str, sc: &mut ScopeContext) -> bool
pub fn field_script_value(&mut self, name: &str, sc: &mut ScopeContext) -> bool
Expect field name
, if present, to be set to a script value, either a named one (simply name = scriptvaluename
)
or an inline one (can be a simple number, or a range { min max }
, or a full script value definition with limits
and math).
The script value is evaluated in the scope context sc
, so for example if the script value does scope:actor
but
there is no named scope “actor” in the scope context, then a warning is emitted.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_script_value_build_sc<F>(&mut self, name: &str, f: F) -> bool
pub fn field_script_value_build_sc<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_script_value
, but it takes a closure that uses the field key token
as the input to build and output a ScopeContext
. This is a convenient way to associate the root
type with the key
of this field, for clearer warnings. A passed-in ScopeContext
would have to be associated with a key that is further away.
Sourcepub fn field_script_value_no_breakdown_build_sc<F>(
&mut self,
name: &str,
f: F,
) -> bool
pub fn field_script_value_no_breakdown_build_sc<F>( &mut self, name: &str, f: F, ) -> bool
Just like Validator::field_script_value
, but it takes a closure that uses the field key token
as the input to build and output a ScopeContext
. This is a convenient way to associate the root
type with the key
of this field, for clearer warnings. A passed-in ScopeContext
would have to be associated with a key that is further away.
Does not warn if it is an inline script value and the desc
fields in it do not contain valid localizations.
Sourcepub fn fields_script_value(&mut self, name: &str, sc: &mut ScopeContext) -> bool
pub fn fields_script_value(&mut self, name: &str, sc: &mut ScopeContext) -> bool
Just like Validator::field_script_value
, but it it expects any number of name
fields.
Sourcepub fn field_choice(&mut self, name: &str, choices: &[&str]) -> bool
pub fn field_choice(&mut self, name: &str, choices: &[&str]) -> bool
Expect field name
, if present, to be set to one of the listed strings in choices
.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn multi_field_choice(&mut self, name: &str, choices: &[&str]) -> bool
pub fn multi_field_choice(&mut self, name: &str, choices: &[&str]) -> bool
Just like Validator::field_choice
, but expect any number of name
fields in the block.
Sourcepub fn field_list(&mut self, name: &str) -> bool
pub fn field_list(&mut self, name: &str) -> bool
Expect field name
, if present, to be of the form name = { value value value ... }
with any number of values.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_validated_list<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated_list<F>(&mut self, name: &str, f: F) -> bool
Expect field name
, if present, to be of the form name = { value value value ... }
with any number of values.
Expect no more than one name
field in the block.
Calls the closure f(value, data)
for every value in the list.
Returns true iff the field is present.
Sourcepub fn field_list_items(&mut self, name: &str, item: Item) -> bool
pub fn field_list_items(&mut self, name: &str, item: Item) -> bool
Expect field name
, if present, to be of the form name = { value value value ... }
with any number of values.
Expect every value to be an itype
item in the game database.
Expect no more than one name
field in the block.
Returns true iff the field is present.
Sourcepub fn field_list_choice(&mut self, name: &str, choices: &[&str]) -> bool
pub fn field_list_choice(&mut self, name: &str, choices: &[&str]) -> bool
Expect field name
, if present, to be of the form name = { value value value ... }
with any number of values.
Expect every value to be an entry from the choices array.
Expect no more than one name
field in the block.
Returns true iff the field is present.
pub fn field_icon(&mut self, name: &str, define: &str, suffix: &str) -> bool
Sourcepub fn multi_field_validated_list<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated_list<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_list
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_list_items(&mut self, name: &str, item: Item) -> bool
pub fn multi_field_list_items(&mut self, name: &str, item: Item) -> bool
Just like Validator::field_list_items
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_value(&mut self, name: &str) -> Vec<&Token>
pub fn multi_field_value(&mut self, name: &str) -> Vec<&Token>
Just like Validator::field_value
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_item(&mut self, name: &str, itype: Item)
pub fn multi_field_item(&mut self, name: &str, itype: Item)
Just like Validator::field_item
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_any_cmp(&mut self, name: &str) -> bool
pub fn multi_field_any_cmp(&mut self, name: &str) -> bool
Just like Validator::field_any_cmp
, but expect any number of name
fields in the block.
Sourcepub fn field_validated<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated<F>(&mut self, name: &str, f: F) -> bool
Expect field name
, if present, to be either an assignment (= value
) or a definition (= { block }
).
Expect no more than one name
field in the block.
Calls the closure f(bv, data)
for every matching field.
Returns true iff the field is present.
Sourcepub fn field_validated_key<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated_key<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated
, but the closure is f(key, bv, data)
.
Sourcepub fn field_validated_sc<F>(
&mut self,
name: &str,
sc: &mut ScopeContext,
f: F,
) -> bool
pub fn field_validated_sc<F>( &mut self, name: &str, sc: &mut ScopeContext, f: F, ) -> bool
Just like Validator::field_validated
, but the closure is f(bv, data, sc)
where sc
is
the passed-in ScopeContext
.
This method is useful for delegating to validate_desc
which takes a bv and a sc.
Sourcepub fn field_validated_rooted<F>(
&mut self,
name: &str,
scopes: Scopes,
f: F,
) -> bool
pub fn field_validated_rooted<F>( &mut self, name: &str, scopes: Scopes, f: F, ) -> bool
Just like Validator::field_validated_sc
, but instead of a full ScopeContext
it just gets the scope type
to be used for the root
of a ScopeContext
that is made on the spot. This is a convenient way to associate the
root
type with the key of this field, for clearer warnings. A passed-in ScopeContext
would have to be associated
with a key that is further away.
pub fn field_validated_build_sc<B, F>(&mut self, name: &str, b: B, f: F) -> bool
Sourcepub fn multi_field_validated<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_validated_key<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated_key<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_key
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_validated_sc<F>(
&mut self,
name: &str,
sc: &mut ScopeContext,
f: F,
) -> bool
pub fn multi_field_validated_sc<F>( &mut self, name: &str, sc: &mut ScopeContext, f: F, ) -> bool
Just like Validator::field_validated_sc
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_validated_block<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated_block<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_block
, but expect any number of name
fields in the block.
Sourcepub fn multi_field_validated_block_sc<F>(
&mut self,
name: &str,
sc: &mut ScopeContext,
f: F,
) -> bool
pub fn multi_field_validated_block_sc<F>( &mut self, name: &str, sc: &mut ScopeContext, f: F, ) -> bool
Just like Validator::field_validated_block_sc
, but expect any number of name
fields in the block.
Sourcepub fn field_validated_block<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated_block<F>(&mut self, name: &str, f: F) -> bool
Expect field name
, if present, to be a definition name = { block }
.
Expect no more than one name
field in the block.
Calls the closure f(block, data)
for every matching field.
Returns true iff the field is present.
Sourcepub fn field_validated_key_block<F>(&mut self, name: &str, f: F) -> bool
pub fn field_validated_key_block<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_block
, but the closure is f(key, block, data)
.
pub fn field_validated_block_build_sc<B, F>( &mut self, name: &str, b: B, f: F, ) -> bool
Sourcepub fn multi_field_validated_key_block<F>(&mut self, name: &str, f: F) -> bool
pub fn multi_field_validated_key_block<F>(&mut self, name: &str, f: F) -> bool
Just like Validator::field_validated_key_block
, but expect any number of name
fields in the block.
Sourcepub fn field_validated_block_sc<F>(
&mut self,
name: &str,
sc: &mut ScopeContext,
f: F,
) -> bool
pub fn field_validated_block_sc<F>( &mut self, name: &str, sc: &mut ScopeContext, f: F, ) -> bool
Just like Validator::field_validated_block
, but the closure is f(block, data, sc)
where sc is the passed-in ScopeContext
.
Sourcepub fn field_validated_block_rooted<F>(
&mut self,
name: &str,
scopes: Scopes,
f: F,
) -> bool
pub fn field_validated_block_rooted<F>( &mut self, name: &str, scopes: Scopes, f: F, ) -> bool
Just like Validator::field_validated_block_sc
, but instead of a full ScopeContext
it just gets the scope type
to be used for the root
of a ScopeContext
that is made on the spot. This is a convenient way to associate the
root
type with the key of this field, for clearer warnings. A passed-in ScopeContext
would have to be associated
with a key that is further away.
Sourcepub fn multi_field_validated_block_rooted<F>(
&mut self,
name: &str,
scopes: Scopes,
f: F,
)
pub fn multi_field_validated_block_rooted<F>( &mut self, name: &str, scopes: Scopes, f: F, )
Just like Validator::field_validated_block_rooted
, but expect any number of name
fields in the block.
Sourcepub fn field_validated_block_rerooted<F>(
&mut self,
name: &str,
sc: &ScopeContext,
scopes: Scopes,
f: F,
) -> bool
pub fn field_validated_block_rerooted<F>( &mut self, name: &str, sc: &ScopeContext, scopes: Scopes, f: F, ) -> bool
Just like Validator::field_validated_block_rooted
, but it takes the passed-in ScopeContext
and associates its
root with this field’s key instead of whatever it was associated with before. This is purely to get better warnings.
TODO: get rid of this in favor of making proper ScopeContext
to begin with.
Sourcepub fn multi_field_block(&mut self, name: &str) -> bool
pub fn multi_field_block(&mut self, name: &str) -> bool
Just like Validator::field_block
, but expect any number of name
fields in the block.
Sourcepub fn req_tokens_integers_exactly(&mut self, expect: usize)
pub fn req_tokens_integers_exactly(&mut self, expect: usize)
Expect this Block
to be a block with exactly expect
loose values that are integers.
So it’s of the form { 1 2 3 }
.
Sourcepub fn req_tokens_numbers_exactly(&mut self, expect: usize)
pub fn req_tokens_numbers_exactly(&mut self, expect: usize)
Expect this Block
to be a block with exactly expect
loose values that are numeric with up to 5 decimals.
So it’s of the form { 0.0 0.5 1.0 }
Sourcepub fn field_list_numeric_exactly(&mut self, name: &str, expect: usize)
pub fn field_list_numeric_exactly(&mut self, name: &str, expect: usize)
Expect field name
, if present, to be of the form name = { value value value ... }
with exactly expect
values.
Expect every value to be a number with up to 5 decimals.
Expect no more than one name
field in the block.
Sourcepub fn req_tokens_precise_numbers_exactly(&mut self, expect: usize)
pub fn req_tokens_precise_numbers_exactly(&mut self, expect: usize)
Like Validator::req_tokens_numbers_exactly
but the numbers can have any number of decimals.
Sourcepub fn field_list_precise_numeric_exactly(&mut self, name: &str, expect: usize)
pub fn field_list_precise_numeric_exactly(&mut self, name: &str, expect: usize)
Like Validator::field_list_numeric_exactly
but the numbers can have any number of decimals.
Sourcepub fn field_list_integers_exactly(&mut self, name: &str, expect: usize)
pub fn field_list_integers_exactly(&mut self, name: &str, expect: usize)
Like Validator::field_list_numeric_exactly
but the numbers have to be integers.
Sourcepub fn values(&mut self) -> Vec<&Token>
pub fn values(&mut self) -> Vec<&Token>
Expect the block to contain any number of loose values (possibly in addition to other things). Return a vector of those values. TODO: make this take a closure or make it an iterator.
Sourcepub fn blocks(&mut self) -> Vec<&Block>
pub fn blocks(&mut self) -> Vec<&Block>
Expect the block to contain any number of loose sub-blocks (possibly in addition to other things).
Return a vector of those blocks.
TODO: make callers use validated_blocks
instead.
Sourcepub fn validated_blocks<F>(&mut self, f: F)
pub fn validated_blocks<F>(&mut self, f: F)
Expect the block to contain any number of loose sub-blocks (possibly in addition to other things).
Run the closure f(block, data)
for every sub-block.
Sourcepub fn integer_blocks(&mut self) -> Vec<(&Token, &Block)>
pub fn integer_blocks(&mut self) -> Vec<(&Token, &Block)>
Expect the block to contain any number of key = { block }
fields where the key is an integer.
Return them as a vector of (key, block) pairs.
TODO: make this take a closure.
Sourcepub fn integer_values(&mut self) -> Vec<(&Token, &Token)>
pub fn integer_values(&mut self) -> Vec<(&Token, &Token)>
Expect the block to contain any number of key = value
fields where the key is an integer.
Return them as a vector of (key, value) pairs.
TODO: make this take a closure.
Sourcepub fn integer_keys<F: FnMut(&Token, &BV)>(&mut self, f: F)
pub fn integer_keys<F: FnMut(&Token, &BV)>(&mut self, f: F)
Expect the block to contain any number of key = value
or key = { block }
fields where the key is an integer.
Return them as a vector of (key, bv) pairs.
TODO: make this take a closure.
Sourcepub fn numeric_keys<F: FnMut(&Token, &BV)>(&mut self, f: F)
pub fn numeric_keys<F: FnMut(&Token, &BV)>(&mut self, f: F)
Expect the block to contain any number of key = value
or key = { block }
fields where the key is a number with up to 5 decimals.
Return them as a vector of (key, bv) pairs.
TODO: make this take a closure.
Sourcepub fn validate_history_blocks<F>(&mut self, f: F)
pub fn validate_history_blocks<F>(&mut self, f: F)
Expect the block to contain any number of key = { block }
fields where the key is a date.
Run the closure f(date, block, data)
for every matching field.
Sourcefn validate_item_key_fields<F>(&mut self, itype: Item, f: F)
fn validate_item_key_fields<F>(&mut self, itype: Item, f: F)
Expect the block to contain any number of key = value
or key = { block }
fields
where each key is a unique Item of type itype.
Run the closure f(key, bv, data)
for every matching block.
Sourcepub fn validate_item_key_values<F>(&mut self, itype: Item, f: F)
pub fn validate_item_key_values<F>(&mut self, itype: Item, f: F)
Expect the block to contain any number of key = value
fields
where each key is a unique Item of type itype.
Run the closure f(key, vd)
for every matching block.
Sourcepub fn validate_item_key_blocks<F>(&mut self, itype: Item, f: F)
pub fn validate_item_key_blocks<F>(&mut self, itype: Item, f: F)
Expect the block to contain any number of key = { block }
fields
where each key is a unique Item of type itype.
Run the closure f(key, block, data)
for every matching block.
Sourcepub fn unknown_fields<F: FnMut(&Token, &BV)>(&mut self, f: F)
pub fn unknown_fields<F: FnMut(&Token, &BV)>(&mut self, f: F)
Expect the block to contain any number of unknown fields (so don’t warn about unknown fields anymore).
Loose values and loose sub-blocks will still be warned about.
Run the closure f(key, bv)
on every matching unknown field. Previously-validated fields will be skipped.
Sourcepub fn unknown_block_fields<F: FnMut(&Token, &Block)>(&mut self, f: F)
pub fn unknown_block_fields<F: FnMut(&Token, &Block)>(&mut self, f: F)
Expect the block to contain any number of unknown key = { block }
fields.
Run the closure f(key, block)
on every matching unknown field. Previously-validated fields will be skipped.
Sourcepub fn unknown_value_fields<F: FnMut(&Token, &Token)>(&mut self, f: F)
pub fn unknown_value_fields<F: FnMut(&Token, &Token)>(&mut self, f: F)
Expect the block to contain any number of unknown key = value
fields.
Run the closure f(key, value)
on every matching unknown field. Previously-validated fields will be skipped.
Sourcepub fn unknown_fields_cmp<F: FnMut(&Token, Comparator, &BV)>(&mut self, f: F)
pub fn unknown_fields_cmp<F: FnMut(&Token, Comparator, &BV)>(&mut self, f: F)
Like Validator::unknown_fields
but passes the comparator, so that f
can determine whether it is =
or ?=
It still expects the comparator to be one of those two.
Sourcepub fn unknown_fields_any_cmp<F: FnMut(&Token, Comparator, &BV)>(
&mut self,
f: F,
)
pub fn unknown_fields_any_cmp<F: FnMut(&Token, Comparator, &BV)>( &mut self, f: F, )
Like Validator::unknown_fields_cmp
but accepts and passes any comparator.
Sourcepub fn no_warn_remaining(&mut self)
pub fn no_warn_remaining(&mut self)
Tells the Validator to not warn about any unknown block contents when it goes out of scope. (The default is to warn.)
Sourcepub fn warn_remaining(&mut self) -> bool
pub fn warn_remaining(&mut self) -> bool
Tells the Validator to warn about any unknown block contents right now, before it goes out of scope. It will not warn again when it does go out of scope. Returns true iff any warnings were emitted.
fn expect_eq_qeq(&self, key: &Token, cmp: Comparator)
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Validator<'a>
impl<'a> !RefUnwindSafe for Validator<'a>
impl<'a> Send for Validator<'a>
impl<'a> Sync for Validator<'a>
impl<'a> Unpin for Validator<'a>
impl<'a> !UnwindSafe for Validator<'a>
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<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
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§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.