Function-to-struct Error
⚓ Rust 📅 2026-06-20 👤 surdeus 👁️ 2I am unsure what the issue is, regarding this error. I cannot seem to find information about the reason a function is expected to be Config (my struct?):
error[E0308]: mismatched types
--> src/config.rs:57:2
|
57 | config_read()
| ^^^^^^^^^^^^^ expected `Config`, found `()`
config.rs:
use std::fs;
use std::sync::LazyLock;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Config {
pub cert: Cert,
pub key: Key,
}
#[derive(Debug, Deserialize)]
pub struct Cert {
pub principle: String,
pub validity: String,
}
#[derive(Debug, Deserialize)]
pub struct Key {
pub ca_priv_key: String,
pub user_dir: String,
pub cert_serial: String,
}
pub fn config_read() {
// Get the value of the "$HOME" environment variable.
let home_env = std::env::var("HOME").unwrap();
// Append the configuration-file directory to the "$HOME" environment-variable value.
static config_dir: &str = "/.config/signatory";
// Append the configuration-file filename to the configuration-file directory.
let config_file = [home_env.clone(), config_dir.to_string(), "/config.toml".to_string()].join("");
// Parse the keys inside of the configuration-file.
let config_file_parse = fs::read_to_string(&config_file).unwrap();
let config: Config = toml::from_str(&config_file_parse).unwrap();
// Set the values of the OpenSSH-generation for-loop to the values of the configuration-file keys.
let ca_priv_key = config.key.ca_priv_key;
let user_dir = config.key.user_dir;
let cert_serial = config.key.cert_serial;
let principle = config.cert.principle;
let validity = config.cert.validity;
}
// Allow the configuration-file structs to be referenced in the OpenSSH-certificate generation code (see generate.rs).
pub static CONFIG: LazyLock<Config> = LazyLock::new (|| {
config_read()
});
3 posts - 2 participants
🏷️ Rust_feed