Struct cjval::CJValidator

source ·
pub struct CJValidator { /* private fields */ }
Expand description

A validator for CityJSON and CityJSONFeature

Implementations§

source§

impl CJValidator

source

pub fn from_str(str_dataset: &str) -> Self

Creates a CJValidator from a &str. Will not return an error here if the &str is not a JSON, only when validate() is called can you see that error.

use cjval::CJValidator;
let s1 = std::fs::read_to_string("./data/cube.city.json")
        .expect("Couldn't read CityJSON file");
let v = CJValidator::from_str(&s1);
source

pub fn from_str_cjfeature(&mut self, str_cjf: &str) -> Result<(), String>

source

pub fn add_one_extension_from_str(&mut self, ext_schema_str: &str) -> Result<()>

Add the content (&str) of an Extension. The library cannot download automatically the Extensions.

use cjval::CJValidator;
let sdata = std::fs::read_to_string("./data/cube.city.json")
        .expect("Couldn't read CityJSON file");
let sext = std::fs::read_to_string("./data/generic.ext.json")
        .expect("Couldn't read JSON file");
let mut val = CJValidator::from_str(&sdata);
let re = val.add_one_extension_from_str(&sext);
source

pub fn is_valid(&self) -> bool

Returns true if the CityJSON/Feature does not contain errors. False otherwise.

source

pub fn validate(&self) -> IndexMap<String, ValSummary>

The function to performs all the checks (errors+warnings). Return a IndexMap (a HashMap where keys are ordered) containing the check name and a ValSummary.

use cjval::CJValidator;
let s1 = std::fs::read_to_string("./data/many.json")
    .expect("Couldn't read CityJSON file");
let v = CJValidator::from_str(&s1);
let re = v.validate();
for (criterion, sum) in re.iter() {
    println!("=== {} ===", criterion);
    println!("{}", sum);
}
source

pub fn get_extensions_urls(&self) -> Option<Vec<String>>

source

pub fn is_cityjsonfeature(&self) -> bool

source

pub fn get_input_cityjson_version(&self) -> i32

source

pub fn get_cityjson_schema_version(&self) -> String

Trait Implementations§

source§

impl Debug for CJValidator

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
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
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, U> TryFrom<U> for T
where 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 T
where 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.