-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make length type generic #256
base: master
Are you sure you want to change the base?
Make length type generic #256
Conversation
812ca47
to
4fb1f1b
Compare
4fb1f1b
to
eefee31
Compare
I'm really interested in this, but it seems like there are conflicts that need to be resolved @JakkuSakura? |
Hi, while it's easy to resolve the conflicts, the potentially breaking semantics should be carefully evaluated by the author, before merging |
Okay, I've opened a PR on your repo with some fun type system hacks that fix the inference for |
…pe-over-new-layout # Conflicts: # src/array_string.rs # src/arrayvec.rs
It's almost perfect let string = ArrayString::<11>::from_byte_string(b"hello world").unwrap(); the only tests that failed was ArrayString without <11>. it's related to the way rust handles inferred type with default type generics. |
Hi folks, I'm also really interested in this feature. Is there anything I could help with to move this forward? |
Well, as you know it's a change where you add something you really want, but we pay with losing some features (type inference, predictability (dependency on capacity), const fn). For any maintainer it's much easier to accept a PR if it's a win-win or if there are only upsides. Differentiated length type was something we had but lost when moving from ad-hoc to const generics, and I think it was worth it. |
The issue with type inference of the However, the problem with some functions such as The advantage of this solution is that it maintains full backward compatibility, the disadvantage is that it makes the implementation more complicated and compilation a bit slower. @bluss, what do you think, would you consider such a PR? |
I would say multiple types is the better path. Or a new type that's always instantiated with a particular capacity type like With that said, I thought there should be some clever way to preserve const fn len. There is an existing mechanism for reducing code duplication - find ArrayVecImpl in the code. The idea is that it provides implementation sharing of different ArrayVec flavors (ArrayVec vs ArrayVecCopy). This needs to be used fully (or find an equivalent but better way to do it) to avoid duplicating the hard code (read: the I'm not concerned about compilation time that much. ArrayVec is generic in the element type, and that means the user doesn't pay much for compilation time unless they instantiate a particular array vec type. No codegen runs for generic items, only monomorphic items. |
It's really a lot of work being done
This PR resolves #247, supersedes #248
However, some things are broken:
type inference won't work for
ArrayVec::from([0; N])
like beforesome functions like
len()
are no longerconst
, unless nightly is enabledThis PR is expected to be merged after #255