Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Pull Request for Issue 101 for no_std #102

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
24 changes: 24 additions & 0 deletions .github/workflows/nostd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
push:
branches: [main]
pull_request:
name: no-std
jobs:
nostd:
runs-on: ubuntu-latest
name: ${{ matrix.target }}
strategy:
matrix:
target: [thumbv7m-none-eabi, aarch64-unknown-none]
steps:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
- uses: actions/checkout@v2
- name: cargo check
uses: actions-rs/cargo@v1
with:
command: check
args: --target ${{ matrix.target }} --no-default-features
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ categories = ["concurrency"]
[dependencies]
slab = "0.4"

[features]
default = ["std"]
std = []

[target.'cfg(loom)'.dependencies]
loom = "0.4.0"
29 changes: 16 additions & 13 deletions src/aliasing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@
//!
//! But this warrants repeating: **your `D` types for `Aliased` _must_ be private**.

use std::marker::PhantomData;
use std::mem::MaybeUninit;
use std::ops::Deref;
use alloc::{boxed::Box, string::String, vec::Vec};
use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::ops::Deref;

// Just to make the doc comment linking work.
#[allow(unused_imports)]
Expand Down Expand Up @@ -183,7 +184,7 @@ where
// a) the T is behind a MaybeUninit, and so will cannot be accessed safely; and
// b) we only expose _either_ &T while aliased, or &mut after the aliasing ends.
Aliased {
aliased: std::ptr::read(&self.aliased),
aliased: core::ptr::read(&self.aliased),
drop_behavior: PhantomData,
_no_auto_send: PhantomData,
}
Expand Down Expand Up @@ -211,7 +212,7 @@ where
pub unsafe fn change_drop<D2: DropBehavior>(self) -> Aliased<T, D2> {
Aliased {
// safety:
aliased: std::ptr::read(&self.aliased),
aliased: core::ptr::read(&self.aliased),
drop_behavior: PhantomData,
_no_auto_send: PhantomData,
}
Expand Down Expand Up @@ -247,7 +248,7 @@ where
// That T has not been dropped (getting a Aliased<T, DoDrop> is unsafe).
// T is no longer aliased (by the safety assumption of getting a Aliased<T, DoDrop>),
// so we are allowed to re-take ownership of the T.
unsafe { std::ptr::drop_in_place(self.aliased.as_mut_ptr()) }
unsafe { core::ptr::drop_in_place(self.aliased.as_mut_ptr()) }
}
}
}
Expand Down Expand Up @@ -276,7 +277,7 @@ where
}
}

use std::hash::{Hash, Hasher};
use core::hash::{Hash, Hasher};
impl<T, D> Hash for Aliased<T, D>
where
D: DropBehavior,
Expand All @@ -290,7 +291,7 @@ where
}
}

use std::fmt;
use core::fmt;
impl<T, D> fmt::Debug for Aliased<T, D>
where
D: DropBehavior,
Expand Down Expand Up @@ -323,7 +324,7 @@ where
D: DropBehavior,
T: PartialOrd,
{
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
self.as_ref().partial_cmp(other.as_ref())
}

Expand All @@ -349,12 +350,12 @@ where
D: DropBehavior,
T: Ord,
{
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.as_ref().cmp(other.as_ref())
}
}

use std::borrow::Borrow;
use core::borrow::Borrow;
impl<T, D> Borrow<T> for Aliased<T, D>
where
D: DropBehavior,
Expand Down Expand Up @@ -385,6 +386,8 @@ where
self.as_ref()
}
}

#[cfg(feature = "std")]
impl<D> Borrow<std::path::Path> for Aliased<std::path::PathBuf, D>
where
D: DropBehavior,
Expand All @@ -410,7 +413,7 @@ where
self.as_ref()
}
}
impl<T, D> Borrow<T> for Aliased<std::sync::Arc<T>, D>
impl<T, D> Borrow<T> for Aliased<alloc::sync::Arc<T>, D>
where
T: ?Sized,
D: DropBehavior,
Expand All @@ -419,7 +422,7 @@ where
self.as_ref()
}
}
impl<T, D> Borrow<T> for Aliased<std::rc::Rc<T>, D>
impl<T, D> Borrow<T> for Aliased<alloc::rc::Rc<T>, D>
where
T: ?Sized,
D: DropBehavior,
Expand Down
Loading