pub struct Context<'r> {
pub root_schema: Option<&'r RootSchema<'r>>,
pub current_schema: Option<&'r YamlSchema<'r>>,
pub current_path: Vec<String>,
pub stream_started: bool,
pub stream_ended: bool,
pub errors: Rc<RefCell<Vec<ValidationError>>>,
pub fail_fast: bool,
pub resolving_refs: Rc<RefCell<HashSet<(String, usize)>>>,
}Expand description
The validation context
Fields§
§root_schema: Option<&'r RootSchema<'r>>We use an Option here so tests can be run without a root schema
current_schema: Option<&'r YamlSchema<'r>>§current_path: Vec<String>§stream_started: bool§stream_ended: bool§errors: Rc<RefCell<Vec<ValidationError>>>§fail_fast: bool§resolving_refs: Rc<RefCell<HashSet<(String, usize)>>>Tracks ($ref, value_position) pairs currently being resolved to detect circular references.
The value position is the byte offset of the YAML value’s span start, so the same ref
applied to a nested value is allowed (legitimate recursion) while the same ref
on the same value is detected as a cycle.
Implementations§
Source§impl<'r> Context<'r>
impl<'r> Context<'r>
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if there are any errors in the context
pub fn new(fail_fast: bool) -> Context<'r>
pub fn get_sub_context(&self) -> Context<'r>
pub fn with_root_schema( root_schema: &'r RootSchema<'_>, fail_fast: bool, ) -> Context<'r>
pub fn add_doc_error<V: Into<String>>(&self, error: V)
Sourcepub fn add_error<V: Into<String>>(&self, marked_yaml: &MarkedYaml<'_>, error: V)
pub fn add_error<V: Into<String>>(&self, marked_yaml: &MarkedYaml<'_>, error: V)
Adds an error message to the current context, with the current path and with location marker
Sourcepub fn extend_errors(&self, errors: Vec<ValidationError>)
pub fn extend_errors(&self, errors: Vec<ValidationError>)
Appends all the errors to the current context
Sourcepub fn append_path<V: Into<String>>(&self, path: V) -> Context<'r>
pub fn append_path<V: Into<String>>(&self, path: V) -> Context<'r>
Append a path to the current path
Sourcepub fn is_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>) -> bool
pub fn is_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>) -> bool
Returns true if the given ref is already being resolved for the given
YAML value (identified by its span start index), indicating a cycle.
Sourcepub fn begin_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
pub fn begin_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
Mark a (ref, value_position) pair as currently being resolved.
Sourcepub fn end_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
pub fn end_resolving_ref(&self, ref_name: &str, value: &MarkedYaml<'_>)
Remove a (ref, value_position) pair from the resolving set after resolution completes.