tmontaigu / dbase-rs

Rust library to read & write dBase files.
MIT License
29 stars 30 forks source link

the trait bound `StationRecord: ReadableRecord` is not satisfied #44

Closed danirc closed 1 year ago

danirc commented 1 year ago

I get this error all the time, but from what I understand I shouldn't implement ReadbableRecord, because serde does it for me, as I see in the documentation.

main.rs file

fn main() -> Result<(), dbase::Error> {
    use serde::Deserialize;
    use std::io::{Read, Seek};

    #[derive(Debug, Deserialize)]
    struct StationRecord {
        name: String,
        marker_col: String,
        marker_sym: String,
        line: String,
    }

    let mut reader = dbase::Reader::from_path("tests/data/stations.dbf")?;
    let stations = reader.read_as::<StationRecord>()?;

    assert_eq!(stations[0].name, "Van Dorn Street");
    assert_eq!(stations[0].marker_col, "#0000ff");
    assert_eq!(stations[0].marker_sym, "rail-metro");
    assert_eq!(stations[0].line, "blue");
    Ok(())
}

Dependences Cargo.toml

[dependencies]
dbase = "0.3.0"
serde = { version = "1.0", features = ["derive"] }
danirc commented 1 year ago

The error is returned by the read_as function, The full error: the trait bound StationRecord: ReadableRecord is not satisfied the trait ReadableRecord is implemented for Record

tmontaigu commented 1 year ago

You also need to enable the "serde" feature for dbase, dbase = { version = "0.3.0", features = ["serde"] }

danirc commented 1 year ago

Thank you very much, it works for me. I've been with rust for a short time and I didn't know that I had to declare the dependencies.