Skip to content

Conversation

@Nadrieril
Copy link
Contributor

It is constructed quite straightforwardly from assert_impl_any by
quantifying using a generic function. Sadly it can't actually reuse
assert_impl_any directly because of "using parameter from outer
function" error.

It is constructed quite straightforwardly from `assert_impl_any` by
quantifying using a generic function. Sadly it can't actually reuse
`assert_impl_any` directly because of "using parameter from outer
function" error.
Copy link
Owner

@nvzqz nvzqz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you so much for this! Just one small change, please. 🙂

I was scratching my head forever on how to get this to work. I started thinking thinking up all sorts of shenanigans for this that would require trait impl specialization.

When I asked @killercup how to do this, he was thinking of doing something like:

trait A {
    const VALUE: usize;
}

default impl<T> A for T {
    const VALUE: usize = 0;
}

trait B {}

impl<T: B> A for T {
    const VALUE: usize = 1;
}

And then somehow adding up VALUE and checking if the result is greater than 0.

@Nadrieril
Copy link
Contributor Author

Well, if you're adding up integers you could just as well || booleans together. And the wrapper trick allows for a limited form of emulating specialization. So this idea isn't too different

@nvzqz nvzqz merged commit 23a626e into nvzqz:master Nov 14, 2019
@nvzqz
Copy link
Owner

nvzqz commented Nov 14, 2019

Ah good point. Unfortunately || doesn't work in const yet, but | does.

@Nadrieril Nadrieril deleted the assert_trait_sub_any branch November 14, 2019 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants