-
Got this error message. Spent 2 hours debugging. Can't figure out what is wrong: the trait bound main.rs use serde_json as json;
use std::env;
use std::fs;
mod app;
mod config;
#[tokio::main]
async fn main() {
println!("MacroPanel v0.1.0");
let args: Vec<String> = env::args().collect();
if args.len() == 1 {
println!("No config file provided");
println!("Usage: macropanel <path_to_config_file>");
} else {
let data = fs::read_to_string(args.get(1).unwrap()).expect("Failed to read config file");
println!("Successfully read config file");
let config_file: config::MacroPanelConfigFile =
json::from_str::<config::MacroPanelConfigFile>(&data)
.expect("Failed to decode config file");
println!("Successfully decoded config file");
println!("");
app::main(config_file).await;
}
} config.rs use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub struct MacroPanelAction {
pub name: String,
}
#[derive(Serialize, Deserialize, Clone)]
pub struct MacroPanelConfigFile {
pub actions: Vec<MacroPanelAction>,
} app.rs use crate::config::MacroPanelConfigFile;
use axum::{
body::Body,
handler::{self, Handler},
routing::get,
Router,
};
use std::net::SocketAddr;
pub async fn main(config: MacroPanelConfigFile) {
let config_str: String = serde_json::to_string(&config).unwrap();
async fn root() -> &'static str {
"Hello, World!"
}
let handler = || async move { return config };
let app: axum::routing::Router = Router::new()
.route("/", get(root))
.route("/actions", get(handler));
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
println!("Listening at {}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
} Please help. |
Beta Was this translation helpful? Give feedback.
Answered by
Aworldc
Apr 20, 2023
Replies: 1 comment
-
Last night while i was in bed i thought of a way to fix this: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Aworldc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Last night while i was in bed i thought of a way to fix this:
I rewrote
handler
from the aboveapp.rs
so it read from a file, instead of trying to use an external variable, which i thought was the issue. It worked.