Skip to content

Commit

Permalink
feat(course_database): basic dot serialization with to_dot
Browse files Browse the repository at this point in the history
  • Loading branch information
GenericConfluent committed Mar 4, 2024
1 parent 921630c commit 048d3c0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/course_database.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::anyhow;

Check warning on line 1 in src/course_database.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/finescale/finescale/src/course_database.rs
use core::str::FromStr;
use petgraph::graph::{DiGraph, NodeIndex};
use petgraph::{dot::Dot, graph::{DiGraph, NodeIndex}};
use serde::Deserialize;
use std::fmt;

Expand Down Expand Up @@ -102,6 +102,16 @@ impl From<Course> for DatabaseNode {
}
}

impl fmt::Display for DatabaseNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use DatabaseNode::*;

Check warning on line 107 in src/course_database.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/finescale/finescale/src/course_database.rs
match self {
Or => write!(f, "OR"),
Course(c) => write!(f, "{}", c.id)
}
}
}

/// Abstraction over some way to retrieve course info for simplicity.
/// There must only be one entry for each course.
pub struct CourseDatabase {
Expand All @@ -114,6 +124,12 @@ pub enum Relation {
Coreq,
}

impl fmt::Display for Relation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}

impl TryFrom<&Requirement> for Relation {
type Error = ();

Expand Down Expand Up @@ -215,6 +231,10 @@ impl CourseDatabase {
_ => unreachable!(),
})
}

pub fn to_dot(&self) -> String {
format!("{}", Dot::new(&self.courses))
}
}

#[cfg(test)]
Expand Down

0 comments on commit 048d3c0

Please sign in to comment.