What does `Result` look like when serde type checking fails

I've this:

#[derive(Serialize, Deserialize, Debug)]
pub struct ProjectSettings {
    #[serde(rename = "short-id")]
    pub short_id: String,
    #[serde(rename = "full-id")]
    pub full_id: String,

pub enum ProjectSettingsError {

pub fn read_project_settings<S: AsRef<str>>(dir: S) -> Result<ProjectSettings, ProjectSettingsError> {
    let project_settings_path = Path::new(dir.as_ref()).join("Flx.toml");
    if !(project_settings_path.exists() && project_settings_path.is_file()) {
        return Err(ProjectSettingsError::NotFound);
    // do `let cfg = toml::from_str();`

As you can see, read_project_settings is still unimplemented. I want to catch any type check error in regards to the fields present in TOML. For example, Flx.toml should look like this:

short-id = "$projectshortid"
full-id = "$projectfullid"

Possibly, the user can omit any of these required fields or assign them with the wrong type. I'm finding serde documentation vague in these regards. Any idea?

In serde, the error type is up to the Deserializer implementation, and the only requirement on it is that it can be constructed from a report of invalid structure; not that you can get that information back out of it. So, you will have to consult the specific deserializer implementation you are using.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.