Open damooo opened 2 years ago
Could you clarify a bit more what you're trying to do?
I want to construct a hlist of tokens, all satisfying certain trait called AdjectiveToken
. So that i can keep that as a valu to list of adjective tokens. I want it to be HList
, instead of Vec<Box<dyn AdjectiveToken>>
as i should be able to specify adjective tokens as trait bounds whrere the struct is expected.
Does this do what you want?
impl<Head, Tail> AdjectiveToken for HCons<Head, Tail>
where
Head: AdjectiveToken,
Tail: AdjectiveToken,
{ ... }
impl AdjectiveToken for HNil { ... }
fn function_which_needs_all_hlist_elements_to_be_tokens<Head, Tail>(hlist: HCons<Head, Tail>)
where
HCons<Head, Tail>: AdjectiveToken
{ ... }
I assume, you meant following:
trait AdjectiveTokenList {}
impl<Head, Tail> AdjectiveTokenList for HCons<Head, Tail>
where
Head: AdjectiveToken,
Tail: AdjectiveTokenList,
{ ... }
impl AdjectiveTokenList for HNil { ... }
fn function_which_needs_all_hlist_elements_to_be_tokens<Head, Tail>(hlist: HCons<Head, Tail>)
where
HCons<Head, Tail>: AdjectiveTokenList
{...}
If so, indeed that is what i mean. But issue is, such an AdjectiveTokenList
cannot implement trait HList
. As HList
requires implementation to allow prepend any unconstrained item in it's trait methods.
Please sketch out the pseudocode of what you're hoping to do in the end, I'm really having a hard time understanding.
Thanks for frunk!
Sorry if this is obvious, but i cannot figure out how to spell out an hlist with all items satisfying a trait bound. Could you help?
Thanks again for your work.