Minor refactorings, type adjustments and typo fixes
This commit is contained in:
parent
78a3ef4a48
commit
f48b2070bc
6 changed files with 14 additions and 20 deletions
|
|
@ -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)
|
||||
})?;
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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()]),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
#[test]
|
||||
fn add() {
|
||||
let e = 0;
|
||||
let n = 0;
|
||||
assert_eq!(e, n);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue