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 {
41 &self.target
42 }
43
44 #[must_use]
46 pub fn operations(&self) -> &[OntologyPatchOperation] {
47 &self.operations
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
53pub enum OntologyPatchOperation {
54 AddImport {
56 import_iri: Iri<String>,
58 },
59 RemoveImport {
61 import_iri: Iri<String>,
63 },
64 AddAnnotation {
66 annotation: Annotation,
68 },
69 RemoveAnnotation {
71 annotation: Annotation,
73 },
74 AddAxiom {
76 axiom: Axiom,
78 },
79 RemoveAxiom {
81 axiom: Axiom,
83 },
84}