Skip to content

Commit e259707

Browse files
committed
Move constructor
1 parent 59c4294 commit e259707

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/valid/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use boon::{Compiler, Schemas};
2-
use serde_json::Value;
31
use std::fs::File;
42
use std::path::{Component, Path};
53
use std::{error::Error, fmt};
64

5+
use boon::{Compiler, Schemas};
6+
use serde_json::Value;
77
use wax::Glob;
88

99
pub struct Validator {
@@ -24,15 +24,15 @@ impl fmt::Display for ValidationError {
2424
write!(f, "Missing meta-spec version")
2525
}
2626
}
27-
pub fn new<P: AsRef<Path>>(dir: P) -> Result<Validator, Box<dyn Error>> {
28-
let compiler = new_compiler(dir)?;
29-
let schemas = Schemas::new();
30-
Ok(Validator { compiler, schemas })
31-
}
32-
3327
const SCHEMA_BASE: &str = "https://pgxn.org/meta/v";
3428

3529
impl Validator {
30+
pub fn new<P: AsRef<Path>>(dir: P) -> Result<Validator, Box<dyn Error>> {
31+
let compiler = new_compiler(dir)?;
32+
let schemas = Schemas::new();
33+
Ok(Validator { compiler, schemas })
34+
}
35+
3636
pub fn validate<'a>(&'a mut self, meta: &'a Value) -> Result<bool, Box<dyn Error + '_>> {
3737
let map = meta.as_object().ok_or(ValidationError::UnknownSpec)?;
3838
let version = map
@@ -139,7 +139,7 @@ mod tests {
139139
fn test_validator() -> Result<(), Box<dyn Error>> {
140140
let schemas_dir: PathBuf = [env!("CARGO_MANIFEST_DIR"), "schema"].iter().collect();
141141

142-
let mut validator = new(schemas_dir)?;
142+
let mut validator = Validator::new(schemas_dir)?;
143143
let valid_file: PathBuf = [
144144
env!("CARGO_MANIFEST_DIR"),
145145
"tests",

tests/common/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub fn test_tags_schema(mut compiler: Compiler, version: u8) -> Result<(), Box<d
187187

188188
pub fn test_schema_version(version: u8) -> Result<(), Box<dyn Error>> {
189189
let mut compiler = Compiler::new();
190+
compiler.enable_format_assertions();
190191
let mut loaded: HashMap<String, Vec<Value>> = HashMap::new();
191192

192193
let paths = fs::read_dir(format!("./schema/v{version}"))?;

0 commit comments

Comments
 (0)