diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..63644e83bea9b5fee8572bdd27dbbbf734065bfa --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + +## [v0.1.0] - 2017-04-27 + +- Initial release + +[Unreleased]: https://github.com/japaric/heapless/compare/v0.1.0...HEAD diff --git a/Cargo.toml b/Cargo.toml index 79634ee5c8cbdbac0c4834ab1a322159e15a4583..34b3177cd989a546eb07aad3ed44fe19b717dbb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,12 @@ [package] +authors = ["Jorge Aparicio <jorge@japaric.io>"] +categories = ["data-structures", "no-std"] +description = "`static` friendly data structures that don't require dynamic memory allocation" +documentation = "https://docs.rs/heapless" +keywords = ["static", "no-heap"] +license = "MIT OR Apache-2.0" name = "heapless" +repository = "https://github.com/japaric/heapless" version = "0.1.0" -authors = ["Jorge Aparicio <japaricious@gmail.com>"] [dependencies] diff --git a/README.md b/README.md index de0ac45ff4d222a8249d72966cf801726477f155..0a79d9eef67e9cf3f902f3fc86d620b8c041acef 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,13 @@ +[](https://crates.io/crates/heapless) +[](https://crates.io/crates/heapless) + # `heapless` -> Heapless, `static` friendly data structures +> `static` friendly data structures that don't require dynamic memory allocation + +# [Documentation](https://docs.rs/heapless) + +# [Change log](CHANGELOG.md) # License diff --git a/src/lib.rs b/src/lib.rs index edaf567c109a5968b89ae354516194474ba66a98..723ea4a83b6da6bd5ee80b352abdd3a2a67d2a27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ -//! Heapless, `static` friendly data structures +//! `static` friendly data structures that don't require dynamic memory +//! allocation #![deny(missing_docs)] #![deny(warnings)] @@ -11,8 +12,9 @@ use core::slice; /// A circular buffer pub struct CircularBuffer<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { _marker: PhantomData<[T]>, array: A, @@ -21,8 +23,9 @@ pub struct CircularBuffer<T, A> } impl<T, A> CircularBuffer<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { /// Creates a new empty circular buffer using `array` as backup storage pub const fn new(array: A) -> Self { @@ -55,8 +58,9 @@ impl<T, A> CircularBuffer<T, A> } impl<T, A> Deref for CircularBuffer<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { type Target = [T]; @@ -73,8 +77,9 @@ impl<T, A> Deref for CircularBuffer<T, A> /// A continuous, growable array type pub struct Vec<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { _marker: PhantomData<[T]>, array: A, @@ -82,8 +87,9 @@ pub struct Vec<T, A> } impl<T, A> Vec<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { /// Creates a new vector using `array` as the backup storage pub const fn new(array: A) -> Self { @@ -99,6 +105,11 @@ impl<T, A> Vec<T, A> self.array.as_ref().len() } + /// Clears the vector, removing all values + pub fn clear(&mut self) { + self.len = 0; + } + /// Removes the last element from this vector and returns it, or `None` if /// it's empty pub fn pop(&mut self) -> Option<T> { @@ -107,8 +118,12 @@ impl<T, A> Vec<T, A> } else { self.len -= 1; unsafe { - Some(*self.array.as_mut().as_mut_ptr().offset(self.len as - isize)) + Some( + *self.array + .as_mut() + .as_mut_ptr() + .offset(self.len as isize), + ) } } } @@ -132,8 +147,9 @@ impl<T, A> Vec<T, A> } impl<T, A> Deref for Vec<T, A> - where A: AsMut<[T]> + AsRef<[T]>, - T: Copy +where + A: AsMut<[T]> + AsRef<[T]>, + T: Copy, { type Target = [T];