158 Commits

Author SHA1 Message Date
Jorge Aparicio
b47d8d8a5d drop no longer required feature gate 2018-10-19 19:49:20 +02:00
Jorge Aparicio
64a76132da use integer_atomics feature instead of core_intrinsics 2018-10-19 19:48:07 +02:00
Jorge Aparicio
9c89b3ea49 cargo fmt 2018-10-19 19:34:00 +02:00
Jorge Aparicio
f83329cbf4 rename RingBuffer to spsc::Queue 2018-10-19 19:28:57 +02:00
Jorge Aparicio
991e4146e1 remove Uxx from the public interface 2018-10-19 14:13:10 +02:00
Jorge Aparicio
150a99726f remove default features
this makes this crate compile on stable by default

this is a breaking change
2018-10-19 14:13:10 +02:00
Jorge Aparicio
836dba1e3d RingBuffer: use the full capacity of the array
Before, to achieve a capacity of 16 elements RingBuffer used an array of 17
elements under the hood. Now the same can be accomplished with an array of 16
elements.

This simplifies the bounds of RingBuffer but it's technically a breaking change.

This change adds an overhead of 1 cycle to the enqueue and dequeue operations.

This commit also documents that using capacities that are powers of two results
in better performance (modulo operations become shifts). This was not documented
before and due to the mismatch of capacity and array size a RB with capacity of
15 performed better than one with a capacity of 16.
2018-10-19 14:13:05 +02:00
Jorge Aparicio
113252f7d8 v0.3.7 v0.3.7 2018-08-19 11:37:45 +02:00
bors[bot]
9037d97263 Merge #55
55: internally use MaybeUninit r=japaric a=japaric

which has been proposed in rust-lang/rfcs#1892

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-08-19 09:22:56 +00:00
Jorge Aparicio
8baf6ec65e internally use MaybeUninit
which has been proposed in rust-lang/rfcs#1892
2018-08-19 11:22:06 +02:00
Jorge Aparicio
13a20aeda6
Merge pull request #54 from japaric/stable
CI: run tests on stable
2018-08-19 10:56:52 +02:00
Jorge Aparicio
8c37d3b3d0 CI: run tests on stable 2018-08-19 10:46:46 +02:00
bors[bot]
e2fbadfd30 Merge #48
48: move more feature gates behind a Cargo feature r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-07-14 00:18:32 +00:00
Jorge Aparicio
baacdf7d7c thumbv6 not supported on beta for now 2018-07-13 19:17:59 -05:00
Jorge Aparicio
bb4f32743f test on beta 2018-07-13 19:08:24 -05:00
Jorge Aparicio
63ae080138 move more feature gates behind a Cargo feature 2018-07-13 19:01:48 -05:00
bors[bot]
930b4964e2 Merge #47
47: RingBuffer: put smaller atomic indices behind a Cargo feature r=japaric a=japaric

cc #40

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-07-13 23:54:37 +00:00
Jorge Aparicio
ae808c9a18 seal the Uxx trait 2018-07-13 18:53:48 -05:00
Jorge Aparicio
ddc6842342 RingBuffer: put smaller atomic indices behind a Cargo feature
this let us drop the core_intrinsics feature gate
2018-07-13 18:51:06 -05:00
bors[bot]
f1b58a8d67 Merge #43
43: Put all const functions behind a const-fn feature r=japaric a=XOSplicer

## Purpose
This PR introduces the `const-fn` feature gate, which when enabled makes most `new` methods `const` 
and therefore usable for initializing `static` variables.
The idea was introduced in #40 with the purpose to come closer to targeting stable rust.
`const` functions are currently only available on rust nightly (tracking issue: [const fn tracking issue (RFC 911)](https://github.com/rust-lang/rust/issues/24111)).
In order to target stable rust this feature is made opt-in.

This feature is a **breaking change** as users of the library now need to explicitly enable it by changing their `Cargo.toml`:
```
...
[dependencies]
heapless = { version = "0.4.0", features = ["const-fn"] }
...
```



## Approach
The implementation of the feature mainly consist of the `const_fn!` macro, which takes a function with `const` modifier
and removes the modifier if the feature gate is not activated.
For the `const` functions a test is intoduced that checks if `static` variables can be initialized.
These tests are only active if the feature is active.
I have not found a way to make doc-test depend on a feature. Therefore some doc-tests are adapted, so that no static initialization is necessary.
The `ci/script.sh` is adapted to also tests with the `--all-feature` flag

## Future
When in the future the `const_fn` rust feature becomes stable, this feature gate **might become active by default**.


Closes #41 .

Co-authored-by: Felix <stegmaier.felix@gmail.com>
Co-authored-by: Felix Stegmaier <stegmaier.felix@gmail.com>
Co-authored-by: Felix Stegmaier <felix.stegmaier@hpe.com>
2018-07-13 17:35:29 +00:00
Felix Stegmaier
6c28c8f62a make feature const-fn default 2018-07-13 11:42:10 +02:00
Felix Stegmaier
40133fea0f Merge remote-tracking branch 'origin/master' into const-fn-feature 2018-07-13 11:25:56 +02:00
bors[bot]
f51e6252ef Merge #46
46: drop the nonzero feature gate r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-07-13 05:29:40 +00:00
Jorge Aparicio
e3c9f23e94 drop the nonzero feature gate 2018-07-13 00:29:08 -05:00
bors[bot]
d2beff0cef Merge #45
45: Fix incorrect length calculation for RingBuffer when head > tail r=japaric a=ReeceStevens

When the head index becomes greater than the tail, the `len()` function returns the incorrect length. This causes iterations over ring buffers to stop early as well, since they use the same calculation.

This PR adds two (very minimal) tests that demonstrate the error.

Co-authored-by: Reece Stevens <reecestevens24@gmail.com>
2018-07-13 04:56:38 +00:00
bors[bot]
f7265774ef Merge #44
44: Added Consumer::ready and Producer::ready indicating if it is ready t… r=japaric a=Frans-Willem

…o enqueue/dequeue.

I needed this to use it with a serial library. e.g. without it:
```
if let Some(x) = serial.read() {
if let Err(x) = producer.enqueue(x) {
// Now what ?
}
}
```
With the ready flag:
```
if producer.ready() {
if let Some(x) = serial.read() {
producer.enqueue(x).unwrap();
}
}
```

Co-authored-by: Frans-Willem Hardijzer <fw@hardijzer.nl>
2018-07-13 04:53:36 +00:00
Reece Stevens
84ce6ec159 Perform same len fix for iterators 2018-06-19 23:29:14 -05:00
Reece Stevens
0172082262 Fix len miscalculation when head > tail 2018-06-19 23:21:14 -05:00
Frans-Willem Hardijzer
34def0f98f Added Consumer::ready and Producer::ready indicating if it is ready to enqueue/dequeue. 2018-06-10 15:05:01 +02:00
Felix Stegmaier
c7bac27100 Enable ci tests with --all-features 2018-05-21 21:27:53 +02:00
Felix Stegmaier
123f489ad6 Add tests for static new methods 2018-05-21 21:19:50 +02:00
Felix Stegmaier
e48b15474d Update docs and tests 2018-05-21 13:18:28 +02:00
Felix Stegmaier
479c74d9e5 Fix static variables in tests 2018-05-19 18:32:47 +02:00
Felix Stegmaier
512ce719ed Fix missing_docs in const_fn macro 2018-05-19 12:25:30 +02:00
Felix
23b301362b WIP const_fn macro 2018-05-19 01:23:10 +02:00
bors[bot]
6ec77ef514 Merge #39
39: Implement FromIterator for Vec r=japaric a=XOSplicer

As discussed in #36 

Panics when the vector can not hold all values supplied by the iterator.
Calling `unwrap` on the result might not be the best choice here.
It might be better to match the result and have a custom panic message.
Is this the best possible behavior?

Co-authored-by: Felix <stegmaier.felix@gmail.com>
Co-authored-by: Felix Stegmaier <stegmaier.felix@gmail.com>
Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-05-14 16:57:11 +00:00
Jorge Aparicio
a4d4d24d46
restore #[test] that got lost in the rebase 2018-05-14 18:56:42 +02:00
Jorge Aparicio
65ce6a6161
expect -> ok().expect 2018-05-14 18:50:27 +02:00
Jorge Aparicio
27ee3f8d7d
Merge branch 'master' into vec-fromiter 2018-05-14 18:39:48 +02:00
Jorge Aparicio
3c0daf9f03
rewrite match as expect 2018-05-14 18:37:38 +02:00
bors[bot]
495cace695 Merge #38
38: Implement IntoIter for Vec r=japaric a=XOSplicer

~~This implementation uses vec::reverse and vec::pop to move the content of the vector out of it.~~

It might give more performance to avoid the `reverse` and read each element individually. In the end  the unmoved items need to be dropped.



Co-authored-by: Felix <stegmaier.felix@gmail.com>
Co-authored-by: Felix Stegmaier <stegmaier.felix@gmail.com>
2018-05-14 16:32:21 +00:00
Felix Stegmaier
fe2650423e Rewrite Vec::IntoIter to avoid reversing it 2018-05-08 17:21:08 +02:00
Felix Stegmaier
53c10049aa Change Vec::from_iter to custom panic 2018-05-07 01:28:20 +02:00
Felix
c78441654f Implement FromIterator for Vec 2018-05-06 22:57:19 +02:00
Felix
fd5f4f0b3d Implement IntoIter using vec::reverse and vec::pop 2018-05-05 17:34:16 +02:00
Jorge Aparicio
e7ada67057 v0.3.6 v0.3.6 2018-05-04 10:18:17 +02:00
bors[bot]
93db77df6a Merge #37
37: fix capacity to be N+1 instead of 2*N+1 r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-05-04 08:08:23 +00:00
Jorge Aparicio
747afb5fbb fix capacity to be N+1 instead of 2*N+1 2018-05-04 10:07:49 +02:00
Jorge Aparicio
2e86db4b1e v0.3.5 v0.3.5 2018-05-03 05:45:17 +02:00
bors[bot]
1ea0389486 Merge #35
35: add RingBuffer.enqueue_unchecked r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
2018-05-03 02:53:18 +00:00