Minor refactorings, type adjustments and typo fixes

This commit is contained in:
Juno Takano 2025-12-25 23:56:18 -03:00
commit f48b2070bc
6 changed files with 14 additions and 20 deletions

View file

@ -26,7 +26,7 @@ async fn main() -> io::Result<()> {
})); }));
let graph = populate_graph(); let graph = populate_graph();
let app = en::router::new(&graph); let router = en::router::new(&graph);
let listener = let listener =
tokio::net::TcpListener::bind(&address).await.map_err(|e| { tokio::net::TcpListener::bind(&address).await.map_err(|e| {
@ -42,7 +42,7 @@ async fn main() -> io::Result<()> {
.unwrap_or("<unknown>".to_string()) .unwrap_or("<unknown>".to_string())
); );
axum::serve(listener, app).await.map_err(|e| { axum::serve(listener, router).await.map_err(|e| {
log!("Failed to serve application: {e:#?}"); log!("Failed to serve application: {e:#?}");
io::Error::other(e) io::Error::other(e)
})?; })?;

View file

@ -41,13 +41,13 @@ pub fn new(graph: &Graph) -> Router {
if graph.meta.config.raw_json { if graph.meta.config.raw_json {
router = router.route( router = router.route(
"/graph/json", "/graph/json",
get(|| handlers::fixed::serial(&Format::Json)), get(|| handlers::fixed::serial(&Format::JSON)),
); );
} }
if graph.meta.config.raw_toml { if graph.meta.config.raw_toml {
router = router.route( router = router.route(
"/graph/toml", "/graph/toml",
get(|| handlers::fixed::serial(&Format::Toml)), get(|| handlers::fixed::serial(&Format::TOML)),
); );
} }
} }

View file

@ -11,7 +11,7 @@ pub fn populate_graph() -> Graph {
Ok(s) => s, Ok(s) => s,
Err(e) => format!("Error: {e}"), Err(e) => format!("Error: {e}"),
}; };
let graph = deserialize_graph(&Format::Toml, &toml_source); let graph = deserialize_graph(&Format::TOML, &toml_source);
let nodes = modulate_nodes(&graph.nodes); let nodes = modulate_nodes(&graph.nodes);
@ -107,17 +107,17 @@ fn make_incoming(nodes: &HashMap<String, Node>) -> HashMap<String, Vec<Edge>> {
} }
pub enum Format { pub enum Format {
Toml, TOML,
Json, JSON,
} }
pub fn serialize_graph(out_format: &Format, graph: &Graph) -> String { pub fn serialize_graph(out_format: &Format, graph: &Graph) -> String {
match *out_format { match *out_format {
Format::Toml => match toml::to_string(graph) { Format::TOML => match toml::to_string(graph) {
Ok(s) => s, Ok(s) => s,
Err(e) => e.to_string(), Err(e) => e.to_string(),
}, },
Format::Json => match serde_json::to_string(graph) { Format::JSON => match serde_json::to_string(graph) {
Ok(s) => s, Ok(s) => s,
Err(e) => e.to_string(), Err(e) => e.to_string(),
}, },
@ -126,11 +126,11 @@ pub fn serialize_graph(out_format: &Format, graph: &Graph) -> String {
pub fn deserialize_graph(in_format: &Format, serial: &str) -> Graph { pub fn deserialize_graph(in_format: &Format, serial: &str) -> Graph {
match *in_format { match *in_format {
Format::Toml => match toml::from_str(serial) { Format::TOML => match toml::from_str(serial) {
Ok(g) => g, Ok(g) => g,
Err(error) => Graph::new(Some(error.to_string())), Err(error) => Graph::new(Some(error.to_string())),
}, },
Format::Json => match serde_json::from_str(serial) { Format::JSON => match serde_json::from_str(serial) {
Ok(g) => g, Ok(g) => g,
Err(error) => Graph::new(Some(error.to_string())), Err(error) => Graph::new(Some(error.to_string())),
}, },

View file

@ -112,7 +112,7 @@ fn mk8() -> u16 {
} }
impl Graph { impl Graph {
pub fn new(message: Option<String>) -> Graph { pub fn new(message: Option<&str>) -> Graph {
Graph { Graph {
nodes: HashMap::new(), nodes: HashMap::new(),
root_node: "VoidNode".to_string(), root_node: "VoidNode".to_string(),
@ -141,7 +141,7 @@ impl Graph {
content_language: String::new(), content_language: String::new(),
}, },
version: (0, 1, 0), version: (0, 1, 0),
messages: message.map_or(vec![], |m| vec![m]), messages: message.map_or(vec![], |m| vec![m.to_string()]),
}, },
} }
} }

View file

@ -397,5 +397,5 @@ Syntax|syntax|
content_language = "en" content_language = "en"
footer_credits = false footer_credits = false
footer_text = """ footer_text = """
made by jutty|https://jutty.dev acknowledgements|Acknowledgments |source code|https://codeberg.org/jutty/en made by jutty|https://jutty.dev acknowledgments|Acknowledgments |source code|https://codeberg.org/jutty/en
""" """

View file

@ -1,6 +0,0 @@
#[test]
fn add() {
let e = 0;
let n = 0;
assert_eq!(e, n);
}