Skip to content

Commit 4b493d2

Browse files
authored
Merge pull request #330 from korpling/add-facet
Add facet support to some types
2 parents 607d511 + f4289da commit 4b493d2

7 files changed

Lines changed: 67 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
change also increases performance for several queries in the test set by up to
1515
30%.
1616

17+
### Added
18+
19+
- Added the support for [Facet](https://facet.rs/) to some of the core types
20+
(like `Annotation`, `Component`, etc.) to make it possible to use Facet in the
21+
[Annatto](https://github.com/korpling/annatto/)
22+
1723
## [3.8.3] - 2025-08-12
1824

1925
### Fixed

core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ version = "3.8.3"
1414
binary-layout = "4.0.1"
1515
bincode = "1.2"
1616
clru = "0.6.1"
17+
facet = "0.28.0"
1718
itertools = "0.10"
1819
lazy_static = "1.4"
1920
log = "0.4"
@@ -32,8 +33,6 @@ serde_bytes = "0.11"
3233
serde_derive = "1.0"
3334
smallvec = "1.6"
3435
sstable = "0.11"
35-
strum = "0.21"
36-
strum_macros = "0.21"
3736
tempfile = "3.1"
3837
thiserror = "1"
3938
toml = "0.8"

core/src/types.rs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use facet::Facet;
12
use num_traits::{Bounded, FromPrimitive, Num, ToPrimitive};
23
use serde::Serialize;
34
use serde::de::DeserializeOwned;
@@ -6,8 +7,6 @@ use std::fmt;
67
use std::ops::AddAssign;
78

89
use std::{convert::TryInto, str::FromStr};
9-
use strum::IntoEnumIterator;
10-
use strum_macros::{EnumIter, EnumString};
1110

1211
use super::serializer::{FixedSizeKeySerializer, KeySerializer};
1312
use crate::serializer::KeyVec;
@@ -22,7 +21,9 @@ use std::result::Result as StdResult;
2221
pub type NodeID = u64;
2322

2423
/// The fully qualified name of an annotation.
25-
#[derive(Serialize, Deserialize, Default, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash)]
24+
#[derive(
25+
Facet, Serialize, Deserialize, Default, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash,
26+
)]
2627
pub struct AnnoKey {
2728
/// Name of the annotation.
2829
pub name: String,
@@ -31,7 +32,9 @@ pub struct AnnoKey {
3132
}
3233

3334
/// An annotation with a qualified name and a value.
34-
#[derive(Serialize, Deserialize, Default, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash)]
35+
#[derive(
36+
Facet, Serialize, Deserialize, Default, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash,
37+
)]
3538
pub struct Annotation {
3639
/// Qualified name or unique "key" for the annotation
3740
pub key: AnnoKey,
@@ -40,7 +43,9 @@ pub struct Annotation {
4043
}
4144

4245
/// Directed edge between a source and target node which are identified by their ID.
43-
#[derive(Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash, Default)]
46+
#[derive(
47+
Facet, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Clone, Debug, Hash, Default,
48+
)]
4449
#[repr(C)]
4550
pub struct Edge {
4651
pub source: NodeID,
@@ -135,7 +140,8 @@ pub trait ComponentType:
135140
}
136141

137142
/// A simplified implementation of a `ComponentType` that only has one type of edges.
138-
#[derive(Clone, Eq, PartialEq, PartialOrd, Ord, EnumString, EnumIter, Debug)]
143+
#[derive(Facet, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)]
144+
#[repr(u16)]
139145
pub enum DefaultComponentType {
140146
Edge,
141147
}
@@ -160,7 +166,7 @@ impl fmt::Display for DefaultComponentType {
160166

161167
pub struct DefaultGraphIndex;
162168

163-
#[derive(Serialize, Deserialize)]
169+
#[derive(Facet, Serialize, Deserialize)]
164170
pub struct DefaultGlobalStatistics;
165171

166172
impl ComponentType for DefaultComponentType {
@@ -173,15 +179,27 @@ impl ComponentType for DefaultComponentType {
173179
Ok(DefaultGraphIndex {})
174180
}
175181
fn all_component_types() -> Vec<Self> {
176-
DefaultComponentType::iter().collect()
182+
vec![DefaultComponentType::Edge]
177183
}
178184
fn calculate_global_statistics(_graph: &mut Graph<Self>) -> StdResult<(), ComponentTypeError> {
179185
Ok(())
180186
}
181187
}
182188

189+
impl FromStr for DefaultComponentType {
190+
type Err = GraphAnnisCoreError;
191+
192+
fn from_str(s: &str) -> StdResult<Self, Self::Err> {
193+
if s == "Edge" {
194+
Ok(Self::Edge)
195+
} else {
196+
Err(GraphAnnisCoreError::InvalidComponentType(s.to_string()))
197+
}
198+
}
199+
}
200+
183201
/// Identifies an edge component of the graph.
184-
#[derive(Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Hash, Clone, Debug)]
202+
#[derive(Facet, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Hash, Clone, Debug)]
185203
pub struct Component<CT: ComponentType> {
186204
/// Type of the component
187205
ctype: u16,
@@ -257,3 +275,20 @@ impl NumValue for u64 {}
257275
impl NumValue for u32 {}
258276
impl NumValue for u16 {}
259277
impl NumValue for u8 {}
278+
279+
#[cfg(test)]
280+
mod tests {
281+
use std::str::FromStr;
282+
283+
use crate::{errors::GraphAnnisCoreError, types::DefaultComponentType};
284+
285+
#[test]
286+
fn parse_invalid_component_type() {
287+
let result = DefaultComponentType::from_str("doesnotexist");
288+
assert!(result.is_err());
289+
assert!(matches!(
290+
result.unwrap_err(),
291+
GraphAnnisCoreError::InvalidComponentType(_)
292+
));
293+
}
294+
}

graphannis/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ regex = "1"
2424
[dependencies]
2525
boolean_expression = "0.4"
2626
csv = "1"
27+
facet = "0.28.0"
2728
fs2 = "0.4"
2829
graphannis-core = { path = "../core/", version = "^3" }
2930
itertools = "0.10"

graphannis/src/annis/db/aql/model.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{
33
errors::GraphAnnisError,
44
graph::{Edge, EdgeContainer, GraphStorage, NodeID},
55
};
6+
use facet::Facet;
67
use graphannis_core::{
78
annostorage::ValueSearch,
89
dfs::CycleSafeDFS,
@@ -44,7 +45,18 @@ lazy_static! {
4445

4546
/// Specifies the type of component of the annotation graph. The types of this enum carray certain semantics about the edges of the graph components their are used in.
4647
#[derive(
47-
Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Hash, Clone, Debug, EnumIter, EnumString,
48+
Facet,
49+
Serialize,
50+
Deserialize,
51+
Eq,
52+
PartialEq,
53+
PartialOrd,
54+
Ord,
55+
Hash,
56+
Clone,
57+
Debug,
58+
EnumIter,
59+
EnumString,
4860
)]
4961
#[repr(C)]
5062
pub enum AnnotationComponentType {

graphannis/src/annis/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{fmt::Display, sync::PoisonError};
22

33
use crate::annis::types::LineColumnRange;
4+
45
use graphannis_core::{
56
errors::{ComponentTypeError, GraphAnnisCoreError},
67
types::NodeID,

verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cargo llvm-cov report --ignore-filename-regex '(tests?\.rs)|(capi/.*)' --release
1818

1919
# Use diff-cover (https://github.com/Bachmann1234/diff_cover) and output code coverage compared to main branch
2020
mkdir -p target/llvm-cov/html/
21-
OUTPUT="$(diff-cover target/llvm-cov/tests.lcov --html-report target/llvm-cov/html/patch.html)"
21+
OUTPUT="$(diff-cover target/llvm-cov/tests.lcov --format html:target/llvm-cov/html/patch.html)"
2222
echo "$OUTPUT"
2323
if [ -z "${CI}" ]; then
2424
echo "HTML report available at $PWD/target/llvm-cov/html/patch.html"

0 commit comments

Comments
 (0)