use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum SchemaSyntax {
Compact,
Xml,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SchemaSource {
text: String,
base_uri: String,
syntax: SchemaSyntax,
}
impl SchemaSource {
pub fn new(text: impl Into<String>, base_uri: impl Into<String>, syntax: SchemaSyntax) -> Self {
Self {
text: text.into(),
base_uri: base_uri.into(),
syntax,
}
}
pub fn text(&self) -> &str {
&self.text
}
pub fn base_uri(&self) -> &str {
&self.base_uri
}
pub fn syntax(&self) -> SchemaSyntax {
self.syntax
}
}
pub trait SchemaResolver {
fn resolve(&self, href: &str, base_uri: &str) -> Result<SchemaSource, ResolveError>;
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ResolveError {
message: String,
}
impl ResolveError {
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
impl fmt::Display for ResolveError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.message)
}
}
impl std::error::Error for ResolveError {}