summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 268496f..e079fca 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -14,6 +14,8 @@ use alloc::{format, vec};
use core::fmt;
use core::mem::take;
+mod schema;
+pub use schema::Schema;
#[cfg(test)]
mod tests;
@@ -119,6 +121,12 @@ pub enum Error {
/// None of the errors in the array will be [`Error::Multiple`]'s,
/// and the array will contain at least two elements.
Multiple(Box<[Error]>),
+ /// Bad type in schema
+ SchemaBadType(Location, Box<str>),
+ /// Bad maxlength in schema
+ SchemaBadMaxLength(Location, Box<str>),
+ /// Invalid schema key
+ SchemaBadKey(Location, Box<str>),
}
impl fmt::Display for Error {
@@ -177,6 +185,9 @@ impl fmt::Display for Error {
}
Ok(())
}
+ Self::SchemaBadType(l, t) => write!(f, "{l}: invalid type: {t:?}"),
+ Self::SchemaBadMaxLength(l, m) => write!(f, "{l}: invalid maxlength: {m:?}"),
+ Self::SchemaBadKey(l, k) => write!(f, "{l}: invalid schema key: {k}"),
}
}
}
@@ -752,6 +763,14 @@ impl Configuration {
self.into_iter()
}
+ /// Same as `iter()` (for now), but explicitly marks that keys should be in sorted order.
+ ///
+ /// This is used internally so that we know what we have to fix if `iter()`
+ /// is ever changed to return a non-sorted iterator.
+ fn iter_sorted(&self) -> ConfigurationIter<'_> {
+ self.iter()
+ }
+
fn get_val(&self, key: &str) -> Option<&Value> {
let idx = self.binary_search_for(key).ok()?;
Some(&self.items[idx].1)
@@ -910,13 +929,16 @@ impl Configuration {
}
}
+ /// Parse `self` as a [`Schema`].
+ pub fn to_schema(&self) -> Result<Schema> {
+ Schema::try_from(self)
+ }
+
/// Check that `self` follows the given schema.
///
- /// See the [POM specification](https://www.pom.computer/spec.html) for a description
- /// of schemas.
- pub fn check_against_schema(&self, schema: &Configuration) -> Result<()> {
- _ = schema;
- todo!()
+ /// Equivalent to `schema.check(self)`.
+ pub fn check_against(&self, schema: &Schema) -> Result<()> {
+ schema.check(self)
}
}