Skip to content
Snippets Groups Projects
Commit f515ed9e authored by Jorge Aparicio's avatar Jorge Aparicio
Browse files

v0.1.0

parent 2d8ff5b0
No related branches found
No related tags found
No related merge requests found
# 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
[package] [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" name = "heapless"
repository = "https://github.com/japaric/heapless"
version = "0.1.0" version = "0.1.0"
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
[dependencies] [dependencies]
[![crates.io](https://img.shields.io/crates/v/heapless.svg)](https://crates.io/crates/heapless)
[![crates.io](https://img.shields.io/crates/d/heapless.svg)](https://crates.io/crates/heapless)
# `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 # License
......
//! Heapless, `static` friendly data structures //! `static` friendly data structures that don't require dynamic memory
//! allocation
#![deny(missing_docs)] #![deny(missing_docs)]
#![deny(warnings)] #![deny(warnings)]
...@@ -11,8 +12,9 @@ use core::slice; ...@@ -11,8 +12,9 @@ use core::slice;
/// A circular buffer /// A circular buffer
pub struct CircularBuffer<T, A> pub struct CircularBuffer<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
_marker: PhantomData<[T]>, _marker: PhantomData<[T]>,
array: A, array: A,
...@@ -21,8 +23,9 @@ pub struct CircularBuffer<T, A> ...@@ -21,8 +23,9 @@ pub struct CircularBuffer<T, A>
} }
impl<T, A> CircularBuffer<T, A> impl<T, A> CircularBuffer<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
/// Creates a new empty circular buffer using `array` as backup storage /// Creates a new empty circular buffer using `array` as backup storage
pub const fn new(array: A) -> Self { pub const fn new(array: A) -> Self {
...@@ -55,8 +58,9 @@ impl<T, A> CircularBuffer<T, A> ...@@ -55,8 +58,9 @@ impl<T, A> CircularBuffer<T, A>
} }
impl<T, A> Deref for CircularBuffer<T, A> impl<T, A> Deref for CircularBuffer<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
type Target = [T]; type Target = [T];
...@@ -73,8 +77,9 @@ impl<T, A> Deref for CircularBuffer<T, A> ...@@ -73,8 +77,9 @@ impl<T, A> Deref for CircularBuffer<T, A>
/// A continuous, growable array type /// A continuous, growable array type
pub struct Vec<T, A> pub struct Vec<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
_marker: PhantomData<[T]>, _marker: PhantomData<[T]>,
array: A, array: A,
...@@ -82,8 +87,9 @@ pub struct Vec<T, A> ...@@ -82,8 +87,9 @@ pub struct Vec<T, A>
} }
impl<T, A> Vec<T, A> impl<T, A> Vec<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
/// Creates a new vector using `array` as the backup storage /// Creates a new vector using `array` as the backup storage
pub const fn new(array: A) -> Self { pub const fn new(array: A) -> Self {
...@@ -99,6 +105,11 @@ impl<T, A> Vec<T, A> ...@@ -99,6 +105,11 @@ impl<T, A> Vec<T, A>
self.array.as_ref().len() 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 /// Removes the last element from this vector and returns it, or `None` if
/// it's empty /// it's empty
pub fn pop(&mut self) -> Option<T> { pub fn pop(&mut self) -> Option<T> {
...@@ -107,8 +118,12 @@ impl<T, A> Vec<T, A> ...@@ -107,8 +118,12 @@ impl<T, A> Vec<T, A>
} else { } else {
self.len -= 1; self.len -= 1;
unsafe { unsafe {
Some(*self.array.as_mut().as_mut_ptr().offset(self.len as Some(
isize)) *self.array
.as_mut()
.as_mut_ptr()
.offset(self.len as isize),
)
} }
} }
} }
...@@ -132,8 +147,9 @@ impl<T, A> Vec<T, A> ...@@ -132,8 +147,9 @@ impl<T, A> Vec<T, A>
} }
impl<T, A> Deref for Vec<T, A> impl<T, A> Deref for Vec<T, A>
where A: AsMut<[T]> + AsRef<[T]>, where
T: Copy A: AsMut<[T]> + AsRef<[T]>,
T: Copy,
{ {
type Target = [T]; type Target = [T];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment