json-ld
json-ld copied to clipboard
Get rid of the `trait_alias` feature.
The trait_alias feature seems far from stabilization. It is currently used to combine complicated where bounds on JSON values that are repeated everywhere in the code.
where bounds are not propagated using super traits bounds:
pub trait Foo where bounds { ... }
// where bounds need to be repeated here
// even though it is part of the definition of `Foo`.
fn bar<F: Foo>(t: F) where bounds { ... }
This can be solved using trait aliases:
pub trait Foo = ... where bounds;
// where bounds don't need to be repeated here.
// they are propagated from the trait alias definition.
fn bar<F: Foo>(t: F) { ... }
Using trait alias has proved that the JSON abstraction layer can work. However with the release of version 1.0, it seems not reasonable to keep relying on an unstable feature.
Possible solution
Maybe we can use macros containing the where bounds to replace trait aliases.
macro_rules! foo {
($f:ident) => { bounds };
}
fn bar<F>(t: F) where foo!(F) { ... }
The tradeoffs are:
- This complicates the source code.
- This may complicate the documentation a lot, by listing a lot of bounds that where previously hidden in trait aliases.
Btw, the "possible solution" does not work: macro calls are not allowed as trait bounds.
This is fixed by https://github.com/timothee-haudebourg/json-ld/pull/37, right?
Yes it is, thanks.