Skip to content
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

Using Serde Derive with database containing Memo field #81

Open
dbristow-otc opened this issue Jan 16, 2024 · 1 comment
Open

Using Serde Derive with database containing Memo field #81

dbristow-otc opened this issue Jan 16, 2024 · 1 comment

Comments

@dbristow-otc
Copy link

I have a dbase file that contains a Memo field, however I'm not sure what type I should put in the structure, and there doesn't appear to be any way to skip over a field.

#[derive(serde::Deserialize)]
pub struct Record {
    #[serde(rename = "DESCRIPTION")]
    description: Option<String>
}

fn main() {
    let mut reader = dbase::Reader::from_path("existing_database.dbf").unwrap();
    let records = reader.read_as::<Record>();

    dbg!(records);
}

This returns the following error:

[src\main.rs:90] records = Err(
    Error {
        record_num: 0,
        field: Some(
            FieldInfo {
                name: "DESCRIPTION",
                field_type: Memo,
                // trimmed extra data
        ),
        kind: BadConversion(
            FieldTypeNotAsExpected {
                expected: Character,
                actual: Memo,
            },
        ),
    },
)

As a workaround, I implemented the unit type in de.rs and simply make the type ():

index 3a7037b..d487227 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -219,11 +219,13 @@ where
         }
     }
 
-    fn deserialize_unit<V>(self, _visitor: V) -> Result<<V as Visitor<'de>>::Value, Self::Error>
+    fn deserialize_unit<V>(self, visitor: V) -> Result<<V as Visitor<'de>>::Value, Self::Error>
     where
         V: Visitor<'de>,
     {
-        unimplemented!("DBase cannot deserialize unit")
+        self.skip_next_field()?;
+        visitor.visit_unit()
     }
 
     fn deserialize_unit_struct<V>(

Is there another type that I should be using? It would be nice to not skip over this field in the future if I end up needing it.

@tmontaigu
Copy link
Owner

Hum, no at the moment there is nothing that connects Memo fields with serde
maybe we can do something about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants