Skip to content

Commit

Permalink
Add no_std support and CI check for embedded (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
PTaylor-us authored Apr 18, 2020
1 parent 80b74d0 commit 4f219e2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,45 @@ jobs:
with:
command: check

check-embedded:
name: Type checking on embedded
runs-on: ${{ matrix.os }}
strategy:
matrix:
rust:
- 1.31.0
- 1.32.0
- 1.33.0
- 1.34.0
- 1.35.0
- 1.36.0
- 1.37.0
- 1.38.0
- 1.39.0
- 1.40.0
- 1.41.0
- 1.42.0
os: [ubuntu-latest]
target: [thumbv7em-none-eabihf]

steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
override: true

- name: Run `cargo check --no-default-features`
uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --target ${{ matrix.target }}

fmt:
name: Formatting
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "standback"
version = "0.2.2"
version = "0.2.3"
authors = ["Jacob Pratt <the.z.cuber@gmail.com>", "The Rust Project Developers"]
edition = "2018"
repository = "https://github.com/jhpratt/standback"
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_camel_case_types, unstable_name_collisions)]
#![cfg_attr(not(std), no_std)]

//! Standback backports a number of methods, structs, and macros that have been
//! stabilized in the Rust standard library since 1.31.0. This allows crate
Expand Down Expand Up @@ -423,12 +424,16 @@ pub mod prelude {
pub use crate::v1_38::{
ConstPtr_v1_38, Duration_v1_38, EuclidFloat_v1_38, Euclid_v1_38, MutPtr_v1_38,
};
#[cfg(all(std, before_1_40))]
pub use crate::v1_40::slice_v1_40;
#[cfg(before_1_40)]
pub use crate::v1_40::{f32_v1_40, f64_v1_40, slice_v1_40, Option_v1_40, Option_v1_40_};
pub use crate::v1_40::{f32_v1_40, f64_v1_40, Option_v1_40, Option_v1_40_};
#[cfg(before_1_41)]
pub use crate::v1_41::Result_v1_41;
#[cfg(all(before_1_42, std))]
pub use crate::v1_42::Condvar_v1_42;
#[cfg(before_1_42)]
pub use crate::v1_42::{Condvar_v1_42, ManuallyDrop_v1_42};
pub use crate::v1_42::ManuallyDrop_v1_42;
#[cfg(before_1_39)]
pub use core::unimplemented as todo;
}
Expand Down
6 changes: 5 additions & 1 deletion src/v1_34.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ mod try_from;

pub use self::try_from::{TryFrom, TryFromIntError, TryInto};
pub use crate::array::TryFromSliceError;
use core::{fmt, iter::FusedIterator, mem};
use core::{fmt, iter::FusedIterator};

#[cfg(std)]
use core::mem;

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Infallible {}
Expand Down Expand Up @@ -106,6 +109,7 @@ pub trait Slice_v1_34<T>: private_slice::Sealed {
K: Ord;
}

#[cfg(std)]
impl<T> Slice_v1_34<T> for [T] {
#[inline]
fn sort_by_cached_key<K, F>(&mut self, f: F)
Expand Down
2 changes: 2 additions & 0 deletions src/v1_38.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ pub trait EuclidFloat_v1_38: private_euclid_float::Sealed {
fn div_euclid(self, rhs: Self) -> Self;
}

#[cfg(std)]
impl EuclidFloat_v1_38 for f32 {
#[must_use = "method returns a new number and does not mutate the original value"]
#[inline]
Expand All @@ -329,6 +330,7 @@ impl EuclidFloat_v1_38 for f32 {
}
}

#[cfg(std)]
impl EuclidFloat_v1_38 for f64 {
#[must_use = "method returns a new number and does not mutate the original value"]
#[inline]
Expand Down
7 changes: 6 additions & 1 deletion src/v1_40.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#[cfg(before_1_32)]
use crate::v1_32::{u32_v1_32, u64_v1_32};
use core::{ops::DerefMut, ptr};
use core::ops::DerefMut;

#[cfg(std)]
use core::ptr;

mod private_option {
pub trait Sealed {}
Expand Down Expand Up @@ -138,12 +141,14 @@ mod private_slice {
impl<T> Sealed for [T] {}
}

#[cfg(std)]
pub trait slice_v1_40<T>: private_slice::Sealed {
fn repeat(&self, n: usize) -> Vec<T>
where
T: Copy;
}

#[cfg(std)]
impl<T: Copy> slice_v1_40<T> for [T] {
fn repeat(&self, n: usize) -> Vec<T> {
if n == 0 {
Expand Down
9 changes: 7 additions & 2 deletions src/v1_42.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use core::{mem::ManuallyDrop, ptr, time::Duration};
use core::{mem::ManuallyDrop, ptr};
#[cfg(std)]
use std::{
sync::{Condvar, LockResult, MutexGuard, WaitTimeoutResult},
time::Instant,
time::{Duration, Instant},
};

#[cfg(std)]
#[inline(always)]
fn new_wait_timeout_result(value: bool) -> WaitTimeoutResult {
// Safety: WaitTimeoutResult is a thin wrapper around a boolean. As the
Expand All @@ -13,11 +15,13 @@ fn new_wait_timeout_result(value: bool) -> WaitTimeoutResult {
unsafe { core::mem::transmute(value) }
}

#[cfg(std)]
mod private_condvar {
pub trait Sealed {}
impl Sealed for super::Condvar {}
}

#[cfg(std)]
pub trait Condvar_v1_42: private_condvar::Sealed {
fn wait_while<'a, T, F>(
&self,
Expand All @@ -36,6 +40,7 @@ pub trait Condvar_v1_42: private_condvar::Sealed {
F: FnMut(&mut T) -> bool;
}

#[cfg(std)]
impl Condvar_v1_42 for Condvar {
fn wait_while<'a, T, F>(
&self,
Expand Down

0 comments on commit 4f219e2

Please sign in to comment.