-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deserializing toml::Value error #816
Comments
We have multiple serializers / deserializers and a feature was likely implemented for one but not another. To address this, we'll need full reproduction steps. |
i m sorry, Table::try_into need an explicit type on trait so this produce success pub trait SettingPath: Sized + DeserializeOwned + Debug {
fn name() -> String {
"Config".to_string()
}
// the location of struct in the tome example local.serial, will just deseialize inside
// [local.serial] in toml file
fn locate() -> impl ToString;
fn get() -> Self {
let file = format!("{}.toml", Self::name());
if let Ok(x) = std::fs::read_to_string(SYSDIR.config_dir(file.clone())) {
println!("de data succes: {:?}", toml::from_str::<Self>(&x).unwrap());
if let Ok(mut data) = toml::from_str::<toml::Value>(&x) {
// for pattern in Self::locate().to_string().split('.') {
// if let toml::Value::Table(table) = data {
// data = table.get(pattern).expect("invalid table name").clone();
// }
// }
return data.try_into::<Self>().expect("invalid deserialize data");
}
}
panic!("{} not found", SYSDIR.config_dir(file));
}
} if i doesnt explicitly type it pub trait SettingPath: Sized + DeserializeOwned + Debug {
fn name() -> String {
"Config".to_string()
}
// the location of struct in the tome example local.serial, will just deseialize inside
// [local.serial] in toml file
fn locate() -> impl ToString;
fn get() -> Self {
let file = format!("{}.toml", Self::name());
if let Ok(x) = std::fs::read_to_string(SYSDIR.config_dir(file.clone())) {
println!("de data succes: {:?}", toml::from_str::<Self>(&x).unwrap());
if let Ok(mut data) = toml::from_str::<toml::Value>(&x) {
// for pattern in Self::locate().to_string().split('.') {
// if let toml::Value::Table(table) = data {
// data = table.get(pattern).expect("invalid table name").clone();
// }
// }
data.try_into().expect("invalid deserialize data")
}
}
panic!("{} not found", SYSDIR.config_dir(file));
}
} this will compile but error when serializing, maybe Try_into try to serialize into the trait itself? i m not really understand it |
Can you provide a complete reproduction case, as in I should be able to drop it into a |
yes this is the full code use serde::{de::DeserializeOwned, Deserialize};
use std::{fmt::Debug, sync::LazyLock};
use sysdir::Sysdir;
pub static SYSDIR: LazyLock<Sysdir> = LazyLock::new(|| Sysdir::custom_name("Roteksia"));
pub trait SettingPath: Sized + DeserializeOwned + Debug {
fn name() -> String {
"Config".to_string()
}
// the location of struct in the tome example local.serial, will just deseialize inside
// [local.serial] in toml file
fn locate() -> impl ToString;
fn get() -> Self {
let file = format!("{}.toml", Self::name());
if let Ok(x) = std::fs::read_to_string(SYSDIR.config_dir(file.clone())) {
if let Ok(mut data) = toml::from_str::<toml::Value>(&x) {
for pattern in Self::locate().to_string().split('.') {
if let toml::Value::Table(table) = data {
data = table.get(pattern).expect("invalid table name").clone();
}
}
data.try_into().expect("invalid deserialize data");
}
}
panic!("{} not found", SYSDIR.config_dir(file));
}
}
#[derive(Clone, Debug, Deserialize)]
pub struct GithubUpdate {
pub repo: String,
pub owner: String,
pub token: Option<String>,
}
impl SettingPath for GithubUpdate {
fn locate() -> impl ToString {
"github"
}
} Config.toml
Sysdir is just my wrapper to handle path, its equal to current dir on debug assertation |
i cant deserialize toml::Value into struct
using direct deserialize result in success, but using table should have success too since its same source
is there something am i missing?
The text was updated successfully, but these errors were encountered: