owl_structural_model/
patch.rs1use iri_rfc3987::Iri;
4
5use crate::{Annotation, Axiom, OntologyId, StructuralModelError};
6
7const KIND_ONTOLOGY_PATCH: &str = "ontology patch";
8
9#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
11pub struct OntologyPatch {
12 target: OntologyId,
13 operations: Vec<OntologyPatchOperation>,
15}
16
17impl OntologyPatch {
18 pub fn try_new(
25 target: OntologyId,
26 operations: Vec<OntologyPatchOperation>,
27 ) -> Result<Self, StructuralModelError> {
28 if operations.is_empty() {
29 return Err(StructuralModelError::InvalidFormat {
30 kind: KIND_ONTOLOGY_PATCH,
31 value: "0 operations".to_owned(),
32 message: "requires at least one operation",
33 });
34 }
35 Ok(Self { target, operations })
36 }
37
38 #[must_use]
40 pub fn target(&self) -> &OntologyId { &self.target }
41
42 #[must_use]
44 pub fn operations(&self) -> &[OntologyPatchOperation] { &self.operations }
45}
46
47#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
49pub enum OntologyPatchOperation {
50 AddImport {
52 import_iri: Iri<String>,
54 },
55 RemoveImport {
57 import_iri: Iri<String>,
59 },
60 AddAnnotation {
62 annotation: Annotation,
64 },
65 RemoveAnnotation {
67 annotation: Annotation,
69 },
70 AddAxiom {
72 axiom: Axiom,
74 },
75 RemoveAxiom {
77 axiom: Axiom,
79 },
80}