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 app = en::router::new(&graph);
let router = en::router::new(&graph);
let listener =
tokio::net::TcpListener::bind(&address).await.map_err(|e| {
@ -42,7 +42,7 @@ async fn main() -> io::Result<()> {
.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:#?}");
io::Error::other(e)
})?;

View file

@ -41,13 +41,13 @@ pub fn new(graph: &Graph) -> Router {
if graph.meta.config.raw_json {
router = router.route(
"/graph/json",
get(|| handlers::fixed::serial(&Format::Json)),
get(|| handlers::fixed::serial(&Format::JSON)),
);
}
if graph.meta.config.raw_toml {
router = router.route(
"/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,
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);
@ -107,17 +107,17 @@ fn make_incoming(nodes: &HashMap<String, Node>) -> HashMap<String, Vec<Edge>> {
}
pub enum Format {
Toml,
Json,
TOML,
JSON,
}
pub fn serialize_graph(out_format: &Format, graph: &Graph) -> String {
match *out_format {
Format::Toml => match toml::to_string(graph) {
Format::TOML => match toml::to_string(graph) {
Ok(s) => s,
Err(e) => e.to_string(),
},
Format::Json => match serde_json::to_string(graph) {
Format::JSON => match serde_json::to_string(graph) {
Ok(s) => s,
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 {
match *in_format {
Format::Toml => match toml::from_str(serial) {
Format::TOML => match toml::from_str(serial) {
Ok(g) => g,
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,
Err(error) => Graph::new(Some(error.to_string())),
},

View file

@ -112,7 +112,7 @@ fn mk8() -> u16 {
}
impl Graph {
pub fn new(message: Option<String>) -> Graph {
pub fn new(message: Option<&str>) -> Graph {
Graph {
nodes: HashMap::new(),
root_node: "VoidNode".to_string(),
@ -141,7 +141,7 @@ impl Graph {
content_language: String::new(),
},
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"
footer_credits = false
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);
}