michael-f-bryan / const-arrayvec Goto Github PK
View Code? Open in Web Editor NEWAn implementation of the arrayvec crate using const generics
Home Page: https://michael-f-bryan.github.io/const-arrayvec
License: Apache License 2.0
An implementation of the arrayvec crate using const generics
Home Page: https://michael-f-bryan.github.io/const-arrayvec
License: Apache License 2.0
I like the distinction between try_insert()
and insert()
. Along those lines, would it make sense for the current push()
to become try_push()
, and implement push()
something like the below?
pub fn push(&mut self, item: T) {
match self.try_push(item) {
Ok(_) => {},
Err(e) => panic!("Push failed: {}", e),
}
}
Is there some reason why <T, const N: usize>
might be preferable to <[T; N]>
? If const generics worked, then anything doable with the former should already be doable with [T; N]
, no? And [T; N]
works out more ergonomic normally, no?
I was sure this was an unsoundness bug but right before I posted I realized it's actually not, but still needs changing IMHO.
try_insert()
checks if the index is bigger then the len index > self.len()
, otherwise panics.
https://github.com/Michael-F-Bryan/const-arrayvec/blob/master/src/lib.rs#L241:L270
Right now it also has a check if the array full, which in my opinion should be removed (you should still be able to insert something on index 2 in a [T; 8] array even if it's full).
BUT removing that check will right now introduce an unsoundness bug, because then you could pass index = len
and it will write out of bound.
the check should be index >= self.len()
because doing [1u8; 8][8]
is obviously out of bound and should panic per rust's semantics.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.