Use Generic Associated Types for Enum trait #35
Conversation
The biggest issue is the length calculation: #[doc(hidden)]
pub const fn enum_len<E: Enum>() -> usize {
E::Array::<()>::LENGTH
} Can we ensure that lengths match for all generic types, and if it doesn't then can we ensure it won't cause unsafety. |
b46a6a7
to
942b6f0
Compare
Do you mean that for given I don't think this can be enforced with rust type system, so probably make it a precondition of some unsafe trait ( Though I am not sure it is actually possible to write such code so it would be different w/o implementing the unsafe |
As far as I understand:
As such, the array size can't change based on Though, allowing the user to implement the |
|
It does. The usual way to seal a trait is to make it require another non-public one. Making the whole trait non-public should work too
Fair, it's just not clear to me what the requirements would be (because it's kinda dependent on |
Have been trying out this feature. One kinda unfortunate thing with current implementation is how I have a generic structure that looks like this: pub struct ActionMap<A: Enum> {
action_map: EnumMap<A, PetitSet<UserInput, 8>>,
} Then, in the code, I want to use With the clone this can be hacked, for example, like this (based on impl of impl<K: Enum, V> Clone for EnumMap<K, V>
where
V: Clone,
{
#[inline]
fn clone(&self) -> Self {
let mut position = 0;
enum_map! {
_k => {
let value = &self.as_slice()[position];
position += 1;
value.clone()
}
}
}
} Unfortunately, this doesn't work with |
- enum-map to a newer version of the GAT PR (KamilaBorowska/enum-map#35) - mp4 to the rebased Hdlr PR (alfg/mp4-rust#95)
enum-map reserves __EnumMapInternalV for this purpose. This is not a part of stable API, and it's only necessary due to not having stable def_site hygiene.
With this PR being closed, are there any plans to bring the GATs in some other form? |
@DCNick3 Right, I forgot to archive the repo. GitHub recommends to close pull requests before archiving, and the project is now migrated to Codeberg where the pull request is still open: https://codeberg.org/xfix/enum-map. |
No description provided.