Skip to content

Commit

Permalink
Fix doc tests
Browse files Browse the repository at this point in the history
Update CI matrix to combine different features

Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Mar 22, 2024
1 parent 4a02aab commit 2693564
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 49 deletions.
72 changes: 54 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@ name: ci
on:
pull_request:
push:
branches:
- master

env:
CARGO_TERM_COLOR: always

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- rust: stable # stable, std
features: ""
- rust: stable # stable, no_std
features: --features no_std
- rust: nightly # nightly, std
features: --features ptr_metadata,allocator_api
- rust: nightly # nightly, no_std
features: --features ptr_metadata,error_in_core,allocator_api,no_std
rust: ["stable", "nightly"]
no_std: [true, false]
debug: [true, false]
unsafe_impl: [true, false]
ptr_metadata: [true, false]
error_in_core: [true, false]
allocator_api: [true, false]
os: [ubuntu-latest, windows-latest, macos-latest]
exclude:
- rust: stable
ptr_metadata: true
- rust: stable
error_in_core: true
- rust: stable
allocator_api: true
- rust: nightly
ptr_metadata: false
- rust: nightly
error_in_core: false
- rust: nightly
allocator_api: false
runs-on: ${{ matrix.os }}
name: |
test - ${{ matrix.os }}, rust ${{ matrix.rust }} (
no_std: ${{ matrix.no_std }},
debug: ${{ matrix.debug }},
unsafe_impl: ${{ matrix.unsafe_impl }},
ptr_metadata: ${{ matrix.ptr_metadata }},
error_in_core: ${{ matrix.error_in_core }},
allocator_api: ${{ matrix.allocator_api }}
)
env:
RUST_BACKTRACE: 1 # Emit backtraces on panics.
steps:
Expand All @@ -32,10 +51,23 @@ jobs:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
- run: cargo test ${{ matrix.features }} --verbose
- if: matrix.no_std == true
run: echo "FEATURES=$FEATURES,no_std" >> $GITHUB_ENV
- if: matrix.debug == true
run: echo "FEATURES=$FEATURES,debug" >> $GITHUB_ENV
- if: matrix.unsafe_impl == true
run: echo "FEATURES=$FEATURES,unsafe_impl" >> $GITHUB_ENV
- if: matrix.ptr_metadata == true
run: echo "FEATURES=$FEATURES,ptr_metadata" >> $GITHUB_ENV
- if: matrix.error_in_core == true
run: echo "FEATURES=$FEATURES,error_in_core" >> $GITHUB_ENV
- if: matrix.allocator_api == true
run: echo "FEATURES=$FEATURES,allocator_api" >> $GITHUB_ENV
- run: cargo test --no-default-features --features=${{ env.FEATURES }} --verbose

lint:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
Expand All @@ -48,11 +80,15 @@ jobs:

miri:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v3
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
rustup override set nightly
cargo miri setup
- run: cargo miri test --all-features --verbose
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
components: miri
override: true
- run: cargo miri setup
- run: cargo miri test --all-features --verbose --color=always
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.check.features": "all",
}
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ keywords = ["memory", "contiguous", "storage", "container", "nostd"]
categories = ["data-structures", "memory-management", "no-std"]
repository = "https://github.com/Caellian/contiguous_mem"

[[example]]
name = "game_loading"
path = "examples/game_loading.rs"
required-features = ["unsafe_impl"]

[[example]]
name = "ptr_metadata"
path = "examples/ptr_metadata.rs"
required-features = ["ptr_metadata"]

[[example]]
name = "unsafe_impl"
path = "examples/unsafe_impl.rs"
required-features = ["unsafe_impl"]

[features]
default = [
"no_std",
"unsafe_impl",
"debug",
"ptr_metadata",
"error_in_core",
"allocator_api",
]
default = ["unsafe_impl", "debug"]

no_std = [] # No-std support
debug = [] # Enable debug attributes
Expand Down
46 changes: 23 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<Impl: ImplDetails<DefaultMemoryManager>> ContiguousMemory<Impl> {
/// # #![allow(unused_mut)]
/// use contiguous_mem::ContiguousMemory;
///
/// let mut storage = ContiguousMemory::new();
/// let mut storage: ContiguousMemory = ContiguousMemory::new();
/// ```
pub fn new() -> Self {
Self {
Expand All @@ -93,7 +93,7 @@ impl<Impl: ImplDetails<DefaultMemoryManager>> ContiguousMemory<Impl> {
/// # #![allow(unused_mut)]
/// use contiguous_mem::ContiguousMemory;
///
/// let mut storage = ContiguousMemory::with_capacity(1024);
/// let mut storage: ContiguousMemory = ContiguousMemory::with_capacity(1024);
/// # assert_eq!(storage.capacity(), 1024);
/// # assert_eq!(storage.align(), core::mem::align_of::<usize>());
/// ```
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<Impl: ImplDetails<DefaultMemoryManager>> ContiguousMemory<Impl> {
/// use core::alloc::Layout;
/// use contiguous_mem::ContiguousMemory;
///
/// let mut storage = ContiguousMemory::with_layout(
/// let mut storage: ContiguousMemory = ContiguousMemory::with_layout(
/// Layout::from_size_align(512, align_of::<u32>()).unwrap()
/// );
/// # assert_eq!(storage.capacity(), 512);
Expand All @@ -151,7 +151,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use contiguous_mem::ContiguousMemory;
/// use contiguous_mem::memory::DefaultMemoryManager;
///
/// let mut storage = ContiguousMemory::with_alloc(
/// let mut storage: ContiguousMemory = ContiguousMemory::with_alloc(
/// DefaultMemoryManager
/// );
/// # assert_eq!(storage.capacity(), 0);
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use contiguous_mem::ContiguousMemory;
/// use contiguous_mem::memory::DefaultMemoryManager;
///
/// let mut storage = ContiguousMemory::with_capacity_and_alloc(
/// let mut storage: ContiguousMemory = ContiguousMemory::with_capacity_and_alloc(
/// 256,
/// DefaultMemoryManager
/// );
Expand Down Expand Up @@ -218,7 +218,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use contiguous_mem::ContiguousMemory;
/// use contiguous_mem::memory::DefaultMemoryManager;
///
/// let mut storage = ContiguousMemory::with_layout_and_alloc(
/// let mut storage: ContiguousMemory = ContiguousMemory::with_layout_and_alloc(
/// Layout::from_size_align(0, align_of::<u32>()).unwrap(),
/// DefaultMemoryManager
/// );
Expand All @@ -234,17 +234,17 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
}
}

/// Returns the base address of the allocated memory.
/// Returns the [`MemoryBase`] of the container.
///
/// # Examples
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// assert_eq!(s.base(), None);
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert!(!s.base().is_allocated());
///
/// let r = s.push(6);
/// assert_eq!(s.base().is_some(), true);
/// assert!(s.base().is_allocated());
/// ```
pub fn base(&self) -> MemoryBase {
*ReadableInner::read(&self.inner.base).expect("can't read base")
Expand All @@ -258,7 +258,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use core::ptr::null;
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(s.base_ptr(), null());
///
/// let r = s.push(3);
Expand All @@ -279,7 +279,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(s.capacity(), 0);
///
/// let r1 = s.push(1u8);
Expand All @@ -305,7 +305,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(s.size(), 0);
///
/// let r1 = s.push(1u8);
Expand Down Expand Up @@ -335,7 +335,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use core::mem::align_of;
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(s.align(), align_of::<usize>());
/// ```
#[inline]
Expand All @@ -351,7 +351,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use core::mem::align_of;
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(
/// s.layout(),
/// Layout::from_size_align(0, align_of::<usize>()).unwrap()
Expand All @@ -373,7 +373,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
/// assert_eq!(s.can_push_t::<u32>(), false);
///
/// let r1 = s.push(1u32);
Expand All @@ -398,7 +398,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// use core::alloc::Layout;
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
///
/// let r1 = s.push([0u32; 4]);
///
Expand Down Expand Up @@ -430,7 +430,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::with_capacity(4);
/// let mut s: ContiguousMemory = ContiguousMemory::with_capacity(4);
/// assert_eq!(s.capacity(), 4);
/// assert_eq!(s.size(), 0);
///
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
///
/// assert!(s.try_grow_to(1024).is_ok());
///
Expand Down Expand Up @@ -620,7 +620,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::with_capacity(4);
/// let mut s: ContiguousMemory = ContiguousMemory::with_capacity(4);
/// assert_eq!(s.capacity(), 4);
///
/// let r = s.push(1u32);
Expand Down Expand Up @@ -657,7 +657,7 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// ```
/// use contiguous_mem::ContiguousMemory;
///
/// let mut s = ContiguousMemory::new();
/// let mut s: ContiguousMemory = ContiguousMemory::new();
///
/// assert!(s.try_reserve_exact(1024).is_ok());
/// assert_eq!(s.capacity(), 1024);
Expand Down Expand Up @@ -879,13 +879,13 @@ impl<Impl: ImplDetails<A>, A: ManageMemory> ContiguousMemory<Impl, A> {
/// # use contiguous_mem::memory::DefaultMemoryManager;
/// # use core::alloc::Layout;
/// # use core::mem;
/// # let mut storage = ContiguousMemory::new();
/// # let mut storage: ContiguousMemory = ContiguousMemory::new();
/// let value = vec!["ignore", "drop", "for", "me"];
/// let erased = &value as *const Vec<&str> as *const ();
/// let layout = Layout::new::<Vec<&str>>();
///
/// // Reference type arguments must be fully specified.
/// let stored: CERef<Vec<&str>, DefaultMemoryManager> = unsafe {
/// let stored: EntryRef<Vec<&str>, DefaultMemoryManager> = unsafe {
/// mem::transmute(storage.push_raw(erased, layout))
/// };
/// ```
Expand Down

0 comments on commit 2693564

Please sign in to comment.