pchampin / sophia_rs

Sophia: a Rust toolkit for RDF and Linked Data
Other
228 stars 24 forks source link

implement serde Serialize and Deserialize for Iri and IriRef? #136

Closed KonradHoeffner closed 1 year ago

KonradHoeffner commented 1 year ago

I am using the config crate to read configuration (requires Deserialize) into my RDF browser, for example the default namespace, which is of Type Iri. Then on rendering the "about" page, a template engine is used to render the config struct into HTML, which requires Serialize. Unfortunately this does not compile because Iri and IriRef do not implement Serialize and Deserialize from serde and it is quite cumbersome to add those manually. Right now I am just using a String for the namespace but that means there is no validation and I need to create a new Iri out of that for every request.

Is it possible to implement Serialize and Deserialize for Iri and IriRef?

pchampin commented 1 year ago

Generally, I'm in favor of making sophia_iri serde-friendly... Howverer, you request is underspecified: Iri and IriRef are generic types, so I guess we should make Iri<T> and IriRef<T> implement Serializable and Deserializable whenever T implements these traits. Would you agree?

KonradHoeffner commented 1 year ago

Oh yes absolutely, I hadn't thought about that as I always use String, I agree that it only makes sense in case T is Serializable respectively Deserializable as well.

pchampin commented 1 year ago

fixed in 81ec89b

In fact, the implementation of Serialize does not depend on T: Serialize, because we can rely on T: Borrow<str>. OTOH, the implementation of Deserialize depends on T: Deserialize.