pub struct ValueValidator<'a> {
value: Cow<'a, Token>,
data: &'a Everything,
validated: bool,
max_severity: Severity,
}Expand description
A validator for one Token.
The intended usage is that the block-level Validator wraps the Token
in a ValueValidator, then you call one or more of the validation functions on it.
If the ValueValidator goes out of scope without having been validated, it will report an error.
Calling multiple validation functions is only supported when starting with the maybe_
variants. Calling one of the definite validation methods will either accept the value or warn
about it, and it’s considered validated after that.
Fields§
§value: Cow<'a, Token>The value being validated
data: &'a EverythingA link to all the loaded and processed CK3 and mod files
validated: boolWhether the value has been validated. If true, it means either the value was accepted as correct or it was warned about.
max_severity: SeverityMaximum severity of problems reported by this ValueValidator. 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.
Implementations§
Source§impl<'a> ValueValidator<'a>
impl<'a> ValueValidator<'a>
Sourcepub fn new(value: &'a Token, data: &'a Everything) -> Self
pub fn new(value: &'a Token, data: &'a Everything) -> Self
Construct a new ValueValidator for a &Token.
Sourcepub fn new_owned(value: Token, data: &'a Everything) -> Self
pub fn new_owned(value: Token, data: &'a Everything) -> Self
Construct a new ValueValidator for an owned Token.
pub fn data(&self) -> &Everything
Sourcepub fn set_max_severity(&mut self, max_severity: Severity)
pub fn set_max_severity(&mut self, max_severity: Severity)
Maximum severity of problems reported by this ValueValidator. 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.
Sourcefn value_validator(&self, token: Token) -> Self
fn value_validator(&self, token: Token) -> Self
Make a descendant validator from this one, usually for a sub-token.
pub fn identifier(&mut self, kind: &'static str)
Sourcepub fn item(&mut self, itype: Item)
pub fn item(&mut self, itype: Item)
Expect the value to be the key of an itype item in the game database.
The item is looked up and must exist.
pub fn icon(&mut self, define: &str, suffix: &str)
Sourcepub fn item_used_with_suffix(&mut self, itype: Item, sfx: &str)
pub fn item_used_with_suffix(&mut self, itype: Item, sfx: &str)
Add the given suffix to the value and mark that as a used item, without doing any validation. This is used for very weakly required localization, for example, where no warning is warranted.
Sourcepub fn implied_localization_sc(
&mut self,
pfx: &str,
sfx: &str,
sc: &mut ScopeContext,
)
pub fn implied_localization_sc( &mut self, pfx: &str, sfx: &str, sc: &mut ScopeContext, )
Validate a localization whose key is derived from the value, in the given ScopeContext.
Sourcepub fn maybe_item(&mut self, itype: Item) -> bool
pub fn maybe_item(&mut self, itype: Item) -> bool
Check if the value is the key of an itype item the game database.
The item is looked up, and if it exists then this validator is considered validated.
Return whether the item exists.
Sourcepub fn maybe_prefix_item(&mut self, pfx: &str, itype: Item) -> bool
pub fn maybe_prefix_item(&mut self, pfx: &str, itype: Item) -> bool
Check if the value is be the key of an itype item the game database, after removing the prefix pfx.
The item is looked up, and if it exists then this validator is considered validated.
Return whether the item exists.
Sourcepub fn dir_file(&mut self, path: &str)
pub fn dir_file(&mut self, path: &str)
Expect the value to be the name of a file under the directory given here.
pub fn split(&mut self, c: char) -> Vec<ValueValidator<'_>>
Sourcepub fn target(&mut self, sc: &mut ScopeContext, outscopes: Scopes)
pub fn target(&mut self, sc: &mut ScopeContext, outscopes: Scopes)
Expect the value to be a (possibly single-element) scope chain which 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.
Sourcepub fn target_ok_this(&mut self, sc: &mut ScopeContext, outscopes: Scopes)
pub fn target_ok_this(&mut self, sc: &mut ScopeContext, outscopes: Scopes)
Just like ValueValidator::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 item_or_target(
&mut self,
sc: &mut ScopeContext,
itype: Item,
outscopes: Scopes,
)
pub fn item_or_target( &mut self, sc: &mut ScopeContext, itype: Item, outscopes: Scopes, )
This is a combination of ValueValidator::item and ValueValidator::target. If the field is present
and is not a known itype item, then it is evaluated as a target.
Sourcepub fn maybe_bool(&mut self)
pub fn maybe_bool(&mut self)
Allow the value to be just yes or no, but don’t mandate it.
Sourcepub fn maybe_integer(&mut self)
pub fn maybe_integer(&mut self)
Allow the value to be an integer, but don’t mandate it.
Sourcepub fn integer_range<R: RangeBounds<i64>>(&mut self, range: R)
pub fn integer_range<R: RangeBounds<i64>>(&mut self, range: R)
Expect the value to be an integer between low and high (inclusive).
Sourcepub fn numeric(&mut self)
pub fn numeric(&mut self)
Expect the value to be a number with up to 5 decimals. (5 decimals is the limit accepted by the game engine in most contexts).
Sourcepub fn numeric_range<R: RangeBounds<f64>>(&mut self, range: R)
pub fn numeric_range<R: RangeBounds<f64>>(&mut self, range: R)
Expect the value to be a number with up to 5 decimals within the range provided.
(5 decimals is the limit accepted by the game engine in most contexts).
Sourcepub fn precise_numeric(&mut self)
pub fn precise_numeric(&mut self)
Expect the value to be a number with any number of decimals.
Sourcepub fn date(&mut self)
pub fn date(&mut self)
Expect the value to be 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).
Sourcepub fn choice(&mut self, choices: &[&str])
pub fn choice(&mut self, choices: &[&str])
Expect the value to be one of the listed strings in choices.
Sourcepub fn maybe_is(&mut self, s: &str) -> bool
pub fn maybe_is(&mut self, s: &str) -> bool
Check if the value is equal to the given string. If it is, mark this value as validated. Return whether the value matched the string.
Sourcepub fn warn_unvalidated(&mut self)
pub fn warn_unvalidated(&mut self)
Tells the ValueValidator to report a warning if the value is still unvalidated.
Trait Implementations§
Source§impl Debug for ValueValidator<'_>
impl Debug for ValueValidator<'_>
Source§impl Display for ValueValidator<'_>
impl Display for ValueValidator<'_>
Source§impl Drop for ValueValidator<'_>
impl Drop for ValueValidator<'_>
Source§impl ErrorLoc for &ValueValidator<'_>
impl ErrorLoc for &ValueValidator<'_>
Source§impl ErrorLoc for &mut ValueValidator<'_>
impl ErrorLoc for &mut ValueValidator<'_>
Auto Trait Implementations§
impl<'a> Freeze for ValueValidator<'a>
impl<'a> !RefUnwindSafe for ValueValidator<'a>
impl<'a> Send for ValueValidator<'a>
impl<'a> Sync for ValueValidator<'a>
impl<'a> Unpin for ValueValidator<'a>
impl<'a> !UnwindSafe for ValueValidator<'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.