Skip to content

Commit 5fa03a6

Browse files
authored
Merge pull request #244 from egohygiene/copilot/introduce-transformation-dag-model
feat: introduce transformation DAG core model
2 parents d74042f + b123a67 commit 5fa03a6

6 files changed

Lines changed: 486 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ notify-debouncer-mini = "0.4"
4949

5050
itertools = "0.14"
5151

52+
petgraph = "0.8"
53+
5254
[package.metadata.generate-rpm]
5355
assets = [
5456
{ source = "target/release/renderflow", dest = "/usr/bin/renderflow", mode = "0755" },

src/graph/format.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use std::fmt;
2+
3+
/// Represents all document formats that can participate in transformation edges.
4+
///
5+
/// Formats are modelled as graph nodes: each variant is a unique node in the
6+
/// [`TransformGraph`](super::TransformGraph). An edge between two nodes
7+
/// indicates that a [`TransformEdge`](super::TransformEdge) exists that can
8+
/// convert from the source format to the target format.
9+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10+
pub enum Format {
11+
Markdown,
12+
Html,
13+
Pdf,
14+
Docx,
15+
Epub,
16+
Rst,
17+
Latex,
18+
}
19+
20+
impl fmt::Display for Format {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
let s = match self {
23+
Format::Markdown => "markdown",
24+
Format::Html => "html",
25+
Format::Pdf => "pdf",
26+
Format::Docx => "docx",
27+
Format::Epub => "epub",
28+
Format::Rst => "rst",
29+
Format::Latex => "latex",
30+
};
31+
write!(f, "{}", s)
32+
}
33+
}
34+
35+
#[cfg(test)]
36+
mod tests {
37+
use super::*;
38+
39+
#[test]
40+
fn test_display_markdown() {
41+
assert_eq!(Format::Markdown.to_string(), "markdown");
42+
}
43+
44+
#[test]
45+
fn test_display_all_variants() {
46+
assert_eq!(Format::Html.to_string(), "html");
47+
assert_eq!(Format::Pdf.to_string(), "pdf");
48+
assert_eq!(Format::Docx.to_string(), "docx");
49+
assert_eq!(Format::Epub.to_string(), "epub");
50+
assert_eq!(Format::Rst.to_string(), "rst");
51+
assert_eq!(Format::Latex.to_string(), "latex");
52+
}
53+
54+
#[test]
55+
fn test_format_equality() {
56+
assert_eq!(Format::Markdown, Format::Markdown);
57+
assert_ne!(Format::Markdown, Format::Html);
58+
}
59+
60+
#[test]
61+
fn test_format_clone_copy() {
62+
let f = Format::Pdf;
63+
let g = f;
64+
assert_eq!(f, g);
65+
}
66+
67+
#[test]
68+
fn test_format_hash() {
69+
use std::collections::HashSet;
70+
let mut set = HashSet::new();
71+
set.insert(Format::Markdown);
72+
set.insert(Format::Markdown);
73+
set.insert(Format::Html);
74+
assert_eq!(set.len(), 2);
75+
}
76+
}

0 commit comments

Comments
 (0)