ValueValidator

Struct ValueValidator 

Source
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 Everything

A link to all the loaded and processed CK3 and mod files

§validated: bool

Whether the value has been validated. If true, it means either the value was accepted as correct or it was warned about.

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

Implementations§

Source§

impl<'a> ValueValidator<'a>

Source

pub fn new(value: &'a Token, data: &'a Everything) -> Self

Construct a new ValueValidator for a &Token.

Source

pub fn new_owned(value: Token, data: &'a Everything) -> Self

Construct a new ValueValidator for an owned Token.

Source

pub fn data(&self) -> &Everything

Source

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.

Source

fn value_validator(&self, token: Token) -> Self

Make a descendant validator from this one, usually for a sub-token.

Source

pub fn value(&self) -> &Token

Access the value that this ValueValidator validates.

Source

pub fn accept(&mut self)

Mark this value as valid, without placing any restrictions on it.

Source

pub fn identifier(&mut self, kind: &'static str)

Source

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.

Source

pub fn icon(&mut self, define: &str, suffix: &str)

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn dir_file(&mut self, path: &str)

Expect the value to be the name of a file under the directory given here.

Source

pub fn split(&mut self, c: char) -> Vec<ValueValidator<'_>>

Source

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.

Source

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.

Source

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.

Source

pub fn bool(&mut self)

Expect the value to be just yes or no.

Source

pub fn maybe_bool(&mut self)

Allow the value to be just yes or no, but don’t mandate it.

Source

pub fn integer(&mut self)

Expect the value to be an integer.

Source

pub fn maybe_integer(&mut self)

Allow the value to be an integer, but don’t mandate it.

Source

pub fn integer_range<R: RangeBounds<i64>>(&mut self, range: R)

Expect the value to be an integer between low and high (inclusive).

Source

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

Source

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

Source

pub fn precise_numeric(&mut self)

Expect the value to be a number with any number of decimals.

Source

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

Source

pub fn choice(&mut self, choices: &[&str])

Expect the value to be one of the listed strings in choices.

Source

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.

Source

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<'_>

Source§

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

Roll our own Debug implementation in order to leave out the data field.

Source§

impl Display for ValueValidator<'_>

Source§

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

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

impl Drop for ValueValidator<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ErrorLoc for &ValueValidator<'_>

Source§

impl ErrorLoc for &mut ValueValidator<'_>

Source§

impl ErrorLoc for 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: Any,

§

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

§

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

§

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

Gets the type name of self
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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
§

impl<T> Downcast for T
where T: AsAny + ?Sized,

§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
§

impl<T> FmtForward for T

§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 T
where T: ?Sized,

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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