Skip to content

Commit 8cc625e

Browse files
committed
Use allocator-api2 as polyfill for allocator API
- Fix a bug where aligning a Range would in some cases cause its length to be negative. - Documentation improvements and fixes. Signed-off-by: Tin Švagelj <[email protected]>
1 parent cccadb2 commit 8cc625e

File tree

13 files changed

+331
-287
lines changed

13 files changed

+331
-287
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,24 @@ jobs:
1818
unsafe_impl: [true, false]
1919
ptr_metadata: [true, false]
2020
error_in_core: [true, false]
21-
allocator_api: [true, false]
2221
exclude:
2322
- rust: stable
2423
ptr_metadata: true
2524
- rust: stable
2625
error_in_core: true
27-
- rust: stable
28-
allocator_api: true
2926
# no point in testing nightly with unstable features disabled
3027
- rust: nightly
3128
ptr_metadata: false
3229
- rust: nightly
3330
error_in_core: false
34-
- rust: nightly
35-
allocator_api: false
3631
runs-on: ${{ matrix.os }}
3732
name: |
3833
test - ${{ matrix.os }}; ${{ matrix.rust }} rust; features: {
3934
no_std: ${{ matrix.no_std }},
4035
debug: ${{ matrix.debug }},
4136
unsafe_impl: ${{ matrix.unsafe_impl }},
4237
ptr_metadata: ${{ matrix.ptr_metadata }},
43-
error_in_core: ${{ matrix.error_in_core }},
44-
allocator_api: ${{ matrix.allocator_api }}
38+
error_in_core: ${{ matrix.error_in_core }}
4539
}
4640
env:
4741
RUST_BACKTRACE: 1 # Emit backtraces on panics.
@@ -62,8 +56,6 @@ jobs:
6256
run: echo "FEATURES=$FEATURES,ptr_metadata" >> $GITHUB_ENV
6357
- if: matrix.error_in_core == true
6458
run: echo "FEATURES=$FEATURES,error_in_core" >> $GITHUB_ENV
65-
- if: matrix.allocator_api == true
66-
run: echo "FEATURES=$FEATURES,allocator_api" >> $GITHUB_ENV
6759
- run: cargo test --no-default-features --features=${{ env.FEATURES }} --verbose
6860

6961
lint:

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ path = "examples/unsafe_impl.rs"
2525
required-features = ["unsafe_impl"]
2626

2727
[features]
28-
default = ["unsafe_impl", "debug"]
28+
default = ["std", "unsafe_impl", "debug"]
2929

30-
no_std = [] # No-std support
31-
debug = [] # Enable debug attributes
30+
std = []
31+
debug = []
3232

3333
# Implementations
3434
unsafe_impl = []
3535

3636
# Nightly features
3737
ptr_metadata = []
3838
error_in_core = []
39-
allocator_api = []
4039

4140
[dependencies]
41+
allocator-api2 = "0.3.0"
4242
sptr = "0.3.2"
4343

4444
[dev-dependencies]

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ the heap to reduce cache misses, but which/how many is determined at runtime.
2525
- Support for dynamic resizing of allocated memory while keeping the existing
2626
references functional (for safe implementations).
2727
- Exhaustively tested with Miri.
28-
- No downstream dependencies.
29-
- ...almost, only [sptr](https://crates.io/crates/sptr) is used to ensure safety.
28+
- Limited downstream dependencies (only polyfills).
29+
- [sptr](https://crates.io/crates/sptr) is used as polyfill for
30+
[Strict Provenance](https://doc.rust-lang.org/beta/unstable-book/language-features/strict-provenance.html)
31+
and required for MIRI.
32+
- [allocator-api2](https://crates.io/crates/allocator-api2)
33+
is used as polyfill for the
34+
[allocator API](https://doc.rust-lang.org/unstable-book/library-features/allocator-api.html).
3035

3136
## Getting Started
3237

@@ -37,11 +42,11 @@ Add the crate to your dependencies:
3742
contiguous_mem = { version = "0.5" }
3843
```
3944

40-
Optionally enable `no_std` feature to use in `no_std` environment:
45+
Disable default features (`std` feature) for use in `no_std` environments:
4146

4247
```toml
4348
[dependencies]
44-
contiguous_mem = { version = "0.5", features = ["no_std"] }
49+
contiguous_mem = { version = "0.5", default-feature = false, features = ["unsafe_impl"] }
4550
```
4651

4752
### Features
@@ -53,8 +58,6 @@ contiguous_mem = { version = "0.5", features = ["no_std"] }
5358
- [`error_in_core`](https://dev-doc.rust-lang.org/stable/unstable-book/library-features/error-in-core.html)
5459
&lt;_nightly_&gt; - enables support for `core::error::Error` in `no_std`
5560
environment
56-
- [`allocator_api`](https://dev-doc.rust-lang.org/stable/unstable-book/library-features/allocator-api.html)
57-
&lt;_nightly_&gt; - enables automatic support for custom allocators
5861
- `unsafe_impl` (default) - enables `UnsafeContiguousMemory`
5962

6063
### Usage
@@ -84,7 +87,8 @@ fn main() {
8487
<sub>* Note that reference types returned by store are inferred and only shown
8588
here for demonstration purposes.</sub>
8689

87-
References have a similar API as [`RefCell`](https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html).
90+
Returned references have semantics similar to
91+
[`RefCell`](https://doc.rust-lang.org/stable/std/cell/struct.RefCell.html).
8892

8993
For more usage examples see the
9094
[examples](https://github.com/Caellian/contiguous_mem/tree/trunk/examples)

doc/crate.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

doc/features.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<table id="feature-table">
2+
<thead>
3+
<tr>
4+
<th><h4>Feature</h4></th>
5+
<th class="vertical"><h4>Default</h4></th>
6+
<th><h4>Description</h4></th>
7+
</tr>
8+
</thead>
9+
<tbody>
10+
<tr>
11+
<td><code>std</code></td>
12+
<td>&check;</td>
13+
<td>enables <code>std</code> types</td>
14+
</tr>
15+
<tr>
16+
<td><code>unsafe_impl</code></td>
17+
<td>&check;</td>
18+
<td>enables <code>UnsafeContiguousMemory</code></td>
19+
</tr>
20+
<tr>
21+
<td><code>debug</code></td>
22+
<td>&cross;</td>
23+
<td>enables <code>derive(Debug)</code> on structures unrelated to error handling</td>
24+
</tr>
25+
</tbody>
26+
<thead>
27+
<tr class="category nightly">
28+
<th colspan="3"><h5>Nightly</h5></th>
29+
</tr>
30+
</thead>
31+
<tbody>
32+
<tr class="nightly">
33+
<td><a href="https://doc.rust-lang.org/beta/unstable-book/library-features/ptr-metadata.html"><code>ptr_metadata</code></a></td>
34+
<td>&cross;</td>
35+
<td>allows casting references into <code>dyn Trait</code></td>
36+
</tr>
37+
<tr class="nightly">
38+
<td><a href="https://dev-doc.rust-lang.org/stable/unstable-book/library-features/error-in-core.html"><code>error_in_core</code></a></td>
39+
<td>&cross;</td>
40+
<td>enables support for <code>core::error::Error</code> in <code>no_std</code> environment</td>
41+
</tr>
42+
</tbody>
43+
</table>
44+
45+
<style>
46+
#feature-table {
47+
.vertical {
48+
vertical-align: bottom;
49+
text-align: center;
50+
width: 2.5em;
51+
52+
>h4 {
53+
writing-mode: vertical-rl;
54+
transform: rotate(180deg);
55+
white-space: nowrap;
56+
margin: auto;
57+
}
58+
}
59+
60+
.category {
61+
th {
62+
padding: .2em;
63+
padding-left: 1em;
64+
}
65+
66+
h5 {
67+
margin: 0;
68+
padding: 0;
69+
text-align: left;
70+
}
71+
72+
&.nightly th {
73+
background: linear-gradient(60deg, #771749, #1da8ae);
74+
color: #fffe;
75+
}
76+
}
77+
78+
tr td:nth-child(1) { text-align: center; }
79+
tr td:nth-child(2) { text-align: center; }
80+
}
81+
</style>

0 commit comments

Comments
 (0)