use std::fmt;
pub const EXTENSION_NAME: &str = "gpkg_schema";
pub const EXTENSION_DEFINITION: &str = "http://www.geopackage.org/spec140/#extension_schema";
pub const EXTENSION_SCOPE: &str = "read-write";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataColumn {
pub column_name: String,
pub name: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub mime_type: Option<String>,
pub constraint_name: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ColumnConstraint {
pub name: String,
pub kind: ConstraintKind,
pub description: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ConstraintKind {
Range {
min: f64,
min_is_inclusive: bool,
max: f64,
max_is_inclusive: bool,
},
Enum(Vec<String>),
Glob(String),
}
impl ConstraintKind {
pub fn type_name(&self) -> &'static str {
match self {
Self::Range { .. } => "range",
Self::Enum(_) => "enum",
Self::Glob(_) => "glob",
}
}
}
impl fmt::Display for ConstraintKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Range {
min,
min_is_inclusive,
max,
max_is_inclusive,
} => write!(
f,
"range {}{min}, {max}{}",
if *min_is_inclusive { '[' } else { '(' },
if *max_is_inclusive { ']' } else { ')' }
),
Self::Enum(members) => write!(f, "enum of {} value(s)", members.len()),
Self::Glob(pattern) => write!(f, "glob {pattern:?}"),
}
}
}