Skip to content

Commit bac48da

Browse files
committed
publish arraydeque 0.1.2
0 parents  commit bac48da

File tree

11 files changed

+3359
-0
lines changed

11 files changed

+3359
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

.travis.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
language: rust
2+
sudo: false
3+
matrix:
4+
include:
5+
- rust: 1.12.0
6+
- rust: stable
7+
env:
8+
- FEATURES="use_generic_array"
9+
- NODEFAULT=1
10+
- rust: beta
11+
- rust: nightly
12+
env:
13+
- NODEFAULT=1
14+
- rust: nightly
15+
env:
16+
- NODROP_FEATURES='use_needs_drop'
17+
- rust: nightly
18+
env:
19+
- FEATURES='use_union use_generic_array'
20+
- NODROP_FEATURES='use_union'
21+
branches:
22+
only:
23+
- master
24+
script:
25+
- |
26+
([ ! -z "$NODROP_FEATURES" ] || cargo build --verbose --features "$FEATURES") &&
27+
([ "$NODEFAULT" != 1 ] || cargo build --verbose --no-default-features) &&
28+
([ ! -z "$NODROP_FEATURES" ] || cargo test --verbose --features "$FEATURES") &&
29+
([ ! -z "$NODROP_FEATURES" ] || cargo test --release --verbose --features "$FEATURES") &&
30+
([ ! -z "$NODROP_FEATURES" ] || cargo bench --verbose --features "$FEATURES" -- --test) &&
31+
([ ! -z "$NODROP_FEATURES" ] || cargo doc --verbose --features "$FEATURES") &&
32+
([ "$NODEFAULT" != 1 ] || cargo build --verbose --manifest-path=nodrop/Cargo.toml --no-default-features) &&
33+
cargo test --verbose --manifest-path=nodrop/Cargo.toml --features "$NODROP_FEATURES" &&
34+
cargo bench --verbose --manifest-path=nodrop/Cargo.toml --features "$NODROP_FEATURES" -- --test

Cargo.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
name = "arraydeque"
3+
version = "0.1.2"
4+
authors = ["goandylok"]
5+
license = "MIT/Apache-2.0"
6+
7+
description = "A ring buffer with a fixed capacity, it can be stored on the stack too. Based on bluss/arrayvec."
8+
repository = "https://github.com/goandylok/arraydeque"
9+
10+
keywords = ["ring", "circular", "buffer", "stack", "vector", "array", "data-structure", "no_std"]
11+
12+
[dependencies.odds]
13+
version = "0.2.12"
14+
default-features = false
15+
16+
[dependencies.nodrop]
17+
version = "0.1.8"
18+
path = "nodrop"
19+
default-features = false
20+
21+
[dependencies.generic-array]
22+
version = "0.5.1"
23+
optional = true
24+
25+
[features]
26+
default = ["std"]
27+
std = ["odds/std", "nodrop/std"]
28+
use_union = ["nodrop/use_union"]
29+
use_generic_array = ["generic-array"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 goandylok
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
#`arraydeque`
2+
3+
A circular buffer with fixed capacity. Requires Rust 1.12+.
4+
5+
This crate is inspired by [**bluss/arrayvec**]
6+
7+
[**bluss/arrayvec**]: https://github.com/bluss/arrayvec
8+
9+
## Feature Flags
10+
11+
The **arraydeque** crate has the following cargo feature flags:
12+
13+
- `std`
14+
- Optional, enabled by default
15+
- Requires Rust 1.6 *to disable*
16+
- Use libstd
17+
18+
19+
- `use_union`
20+
- Optional
21+
- Requires Rust nightly channel
22+
- Use the unstable feature untagged unions for the internal implementation,
23+
which has reduced space overhead
24+
25+
26+
- `use_generic_array`
27+
- Optional
28+
- Requires Rust stable channel
29+
- Depend on generic-array and allow using it just like a fixed
30+
size array for ArrayVec storage.
31+
32+
33+
## Usage
34+
35+
First, add the following to your `Cargo.toml`:
36+
37+
```toml
38+
[dependencies]
39+
arraydeque = "0.1.2"
40+
```
41+
42+
Next, add this to your crate root:
43+
44+
```rust
45+
extern crate arraydeque;
46+
```
47+
48+
Currently arraydeque by default links to the standard library, but if you would
49+
instead like to use arraydeque in a `#![no_std]` situation or crate you can
50+
request this via:
51+
52+
```toml
53+
[dependencies]
54+
arraydeque = { version = "0.1.2", default-features = false }
55+
```
56+
57+
## Example
58+
59+
### Push & Pop
60+
61+
```rust
62+
extern crate arraydeque;
63+
64+
use arraydeque::ArrayDeque;
65+
66+
fn main() {
67+
let mut vector: ArrayDeque<[_; 8]> = ArrayDeque::new();
68+
assert_eq!(vector.capacity(), 7);
69+
assert_eq!(vector.len(), 0);
70+
71+
vector.push_back(1);
72+
vector.push_back(2);
73+
assert_eq!(vector.len(), 2);
74+
75+
assert_eq!(vector.pop_front(), Some(1));
76+
assert_eq!(vector.pop_front(), Some(2));
77+
assert_eq!(vector.pop_front(), None);
78+
}
79+
```
80+
81+
### Insert & Remove
82+
83+
```rust
84+
use arraydeque::ArrayDeque;
85+
86+
let mut vector: ArrayDeque<[_; 8]> = ArrayDeque::new();
87+
88+
vector.push_back(11);
89+
vector.push_back(13);
90+
vector.insert(1, 12);
91+
vector.remove(0);
92+
93+
assert_eq!(vector[0], 12);
94+
assert_eq!(vector[1], 13);
95+
```
96+
97+
### Append & Extend
98+
99+
```rust
100+
use arraydeque::ArrayDeque;
101+
102+
let mut vector: ArrayDeque<[_; 8]> = ArrayDeque::new();
103+
let mut vector2: ArrayDeque<[_; 8]> = ArrayDeque::new();
104+
105+
vector.extend(0..5);
106+
vector2.extend(5..7);
107+
108+
assert_eq!(format!("{:?}", vector), "[0, 1, 2, 3, 4]");
109+
assert_eq!(format!("{:?}", vector2), "[5, 6]");
110+
111+
vector.append(&mut vector2);
112+
113+
assert_eq!(format!("{:?}", vector), "[0, 1, 2, 3, 4, 5, 6]");
114+
assert_eq!(format!("{:?}", vector2), "[]");
115+
```
116+
117+
### Iterator
118+
119+
```rust
120+
use arraydeque::ArrayDeque;
121+
122+
let mut vector: ArrayDeque<[_; 8]> = ArrayDeque::new();
123+
124+
vector.extend(0..5);
125+
126+
let iters: Vec<_> = vector.into_iter().collect();
127+
assert_eq!(iters, vec![0, 1, 2, 3, 4]);
128+
```
129+
130+
### From Iterator
131+
132+
```rust
133+
use arraydeque::ArrayDeque;
134+
135+
let vector: ArrayDeque<[_; 8]>;
136+
let vector2: ArrayDeque<[_; 8]>;
137+
138+
vector = vec![0, 1, 2, 3, 4].into_iter().collect();
139+
140+
vector2 = (0..5).into_iter().collect();
141+
142+
assert_eq!(vector, vector2);
143+
```
144+
145+
### Generic Array
146+
147+
```toml
148+
[dependencies.arraydeque]
149+
version = "0.1.2"
150+
features = ["use_generic_array"]
151+
```
152+
```rust
153+
#[macro_use]
154+
extern crate generic_array;
155+
extern crate arraydeque;
156+
157+
use generic_array::GenericArray;
158+
use generic_array::typenum::U41;
159+
160+
use arraydeque::ArrayDeque;
161+
162+
fn main() {
163+
let mut vec: ArrayDeque<GenericArray<i32, U41>> = ArrayDeque::new();
164+
165+
assert_eq!(vec.len(), 0);
166+
assert_eq!(vec.capacity(), 40);
167+
168+
vec.extend(0..20);
169+
170+
assert_eq!(vec.len(), 20);
171+
assert_eq!(vec.into_iter().take(5).collect::<Vec<_>>(), vec![0, 1, 2, 3, 4]);
172+
}
173+
```
174+
175+
## Contribution
176+
177+
All kinds of contribution are welcomed.
178+
179+
- **Issus.** Feel free to open an issue when you find typos, bugs, or have any question.
180+
- **Pull requests**. New collection, better implementation, more tests, more documents and typo fixes are all welcomed.
181+
182+
## License
183+
184+
Licensed under MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

nodrop-union/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "nodrop-union"
3+
version = "0.1.9"
4+
authors = ["bluss"]
5+
6+
license = "MIT/Apache-2.0"
7+
8+
description = "A wrapper type to inhibit drop (destructor). Implementation crate for nodrop, the untagged unions implementation (which is unstable / requires nightly) as of this writing."
9+
documentation = "http://bluss.github.io/arrayvec/doc/nodrop_union"
10+
repository = "https://github.com/bluss/arrayvec"
11+
12+
keywords = ["container", "drop", "no_std"]
13+

0 commit comments

Comments
 (0)