Skip to content

Optional iterators: Vec<Nested>: LinkedDataSubject<WithGenerator<rdf_types::generator::Blank>> not implemented #6

@Luke-ebbis

Description

@Luke-ebbis

This is a nice macro system! For my usecase, I sometimes have vectors that are missing.

I have adapted the example:

    use linked_data::iref::IriBuf;
    use linked_data::rdf_types::RdfDisplay;
    use rdf_types::iref::Iri;
    use rdf_types::static_iref::iri;


    fn test_ld() -> () {
        #[derive(linked_data::Serialize, linked_data::Deserialize)]
        #[ld(prefix("ex" = "http://example.org/"))]
        struct Foo {
            #[ld(id)]
            id: IriBuf,

            #[ld("ex:name")]
            name: String,

            #[ld("ex:email")]
            email: String,

            #[ld("ex:numbers")]
            numbers: Vec<i64>,
            #[ld("ex:maybe")]
            maybe: Option<String>,
            #[ld("ex:alot")]
            alot: Vec<Nested>,
            #[ld("ex:maybealot")] // does not work
            //  #[ld(ignore)] // does  work
            maybe_alot: Option<Vec<Nested>>,
        }

        #[derive(linked_data::Serialize, linked_data::Deserialize)]
        #[ld(prefix("ex" = "http://example.org/"))]
        #[ld(type = "ex:object")]
        struct Nested {
            #[ld("ex:num")]
            m: i64,
        }

        let value = Foo {
            id: iri!("http://example.org/JohnSmith").to_owned(),
            name: "John Smith".to_owned(),
            email: "john.smith@example.org".to_owned(),
            numbers: vec![1, 133],
            maybe: Some("S".into()),
            alot: vec![Nested { m: 10 }],
            maybe_alot: Some(vec![Nested { m: 10 }]),
        };

        let quads = linked_data::to_quads(rdf_types::generator::Blank::new(), &value)
            .expect("RDF serialization failed");

        dbg!(&quads);

        for quad in quads {
            use rdf_types::RdfDisplay;
            println!("{} .", quad.rdf_display())
        }
    }

This does not work,

error[E0277]: the trait bound `Vec<Nested>: LinkedDataSubject<WithGenerator<rdf_types::generator::Blank>>` is not satisfied
   --> src/biordf/Omicsdi.rs:228:79
    |
228 |         let quads = linked_data::to_quads(rdf_types::generator::Blank::new(), &value)
    |                     ---------------------                                     ^^^^^^ the trait `LinkedDataSubject<WithGenerator<rdf_types::generator::Blank>>` is not implemented for `Vec<Nested>`
    |                     |
    |                     required by a bound introduced by this call
    |
    = help: the following other types implement trait `LinkedDataSubject<I, V>`:
              `&'a T` implements `LinkedDataSubject<I, V>`
              `()` implements `LinkedDataSubject<I, V>`
              `AnonymousBinding<'a, T>` implements `LinkedDataSubject<I, V>`
              `AnonymousGraph<T>` implements `LinkedDataSubject<I, V>`
              `BlankIdBuf` implements `LinkedDataSubject<I, V>`
              `Box<T>` implements `LinkedDataSubject<I, V>`
              `DatasetGraphView<'a, D>` implements `LinkedDataSubject<I, V>`
              `Foo` implements `LinkedDataSubject<I_, V_>`
            and 18 others
    = note: required for `std::option::Option<Vec<Nested>>` to implement `LinkedDataPredicateObjects<WithGenerator<rdf_types::generator::Blank>>`
note: required for `Foo` to implement `LinkedData<WithGenerator<rdf_types::generator::Blank>>`
   --> src/biordf/Omicsdi.rs:188:18
    |
188 |         #[derive(linked_data::Serialize, linked_data::Deserialize)]
    |                  ^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
189 |         #[ld(prefix("ex" = "http://example.org/"))]
190 |         struct Foo {
    |                ^^^
note: required by a bound in `to_quads`
   --> /home/sibbe/.cargo/registry/src/index.crates.io-6f17d22bba15001f/linked-data-0.1.2/src/quads.rs:198:15
    |
196 | pub fn to_quads<G: Generator>(
    |        -------- required by a bound in this function
197 |     generator: G,
198 |     value: &impl LinkedData<interpretation::WithGenerator<G>>,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `to_quads`
    = note: this error originates in the derive macro `linked_data::Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Vec<Nested>: LinkedDataResource<WithGenerator<rdf_types::generator::Blank>>` is not satisfied
   --> src/biordf/Omicsdi.rs:228:79
    |
228 |         let quads = linked_data::to_quads(rdf_types::generator::Blank::new(), &value)
    |                     ---------------------                                     ^^^^^^ the trait `LinkedDataResource<WithGenerator<rdf_types::generator::Blank>>` is not implemented for `Vec<Nested>`
    |                     |
    |                     required by a bound introduced by this call
    |
    = help: the following other types implement trait `LinkedDataResource<I, V>`:
              `&'a T` implements `LinkedDataResource<I, V>`
              `()` implements `LinkedDataResource<I, V>`
              `AnonymousBinding<'a, T>` implements `LinkedDataResource<I, V>`
              `AnonymousGraph<T>` implements `LinkedDataResource<I, V>`
              `BlankIdBuf` implements `LinkedDataResource<I, V>`
              `Box<T>` implements `LinkedDataResource<I, V>`
              `Foo` implements `LinkedDataResource<I_, V_>`
              `IriBuf` implements `LinkedDataResource<I, V>`
            and 21 others
    = note: required for `std::option::Option<Vec<Nested>>` to implement `LinkedDataPredicateObjects<WithGenerator<rdf_types::generator::Blank>>`
note: required for `Foo` to implement `LinkedData<WithGenerator<rdf_types::generator::Blank>>`
   --> src/biordf/Omicsdi.rs:188:18
    |
188 |         #[derive(linked_data::Serialize, linked_data::Deserialize)]
    |                  ^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
189 |         #[ld(prefix("ex" = "http://example.org/"))]
190 |         struct Foo {
    |                ^^^
note: required by a bound in `to_quads`
   --> /home/sibbe/.cargo/registry/src/index.crates.io-6f17d22bba15001f/linked-data-0.1.2/src/quads.rs:198:15
    |
196 | pub fn to_quads<G: Generator>(
    |        -------- required by a bound in this function
197 |     generator: G,
198 |     value: &impl LinkedData<interpretation::WithGenerator<G>>,
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `to_quads`
    = note: this error originates in the derive macro `linked_data::Serialize` (in Nightly builds, run with -Z macro-backtrace for more info)

but if I change #[ld(ex:maybealot")] to #[ld(ignore)], it all works fine.

How may I implement LinkedDataSubject<WithGenerator<rdf_types::generator::Blank>>? I am interested to learn more rust, but I don't yet understand macro programming.

If I get this working, I would love to issue a pull request for the documentation and the derived trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions