Skip to content

Commit

Permalink
Rust 1.47 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Oct 7, 2020
1 parent a56e7fe commit 5526774
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
name: Build

on: [push, pull_request]
on:
push:
branches: ["**"]
tags-ignore: ["**"]
paths-ignore:
- "**.md"
- LICENSE-Apache
- LICENSE-MIT
pull_request:
paths-ignore:
- "**.md"
- LICENSE-Apache
- LICENSE-MIT
schedule:
- cron: "0 0 * * 6" # midnight on Saturdays

jobs:
check:
Expand All @@ -24,6 +38,7 @@ jobs:
- 1.43.1
- 1.44.1
- 1.45.2
- 1.46.0
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
Expand Down Expand Up @@ -69,6 +84,7 @@ jobs:
- 1.43.1
- 1.44.1
- 1.45.2
- 1.46.0
os: [ubuntu-latest]
target: [thumbv7em-none-eabihf]

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.10"
version = "0.2.11"
authors = ["Jacob Pratt <the.z.cuber@gmail.com>", "The Rust Project Developers"]
edition = "2018"
repository = "https://github.com/jhpratt/standback"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use version_check::{Channel, Version};
// We assume that features are never stabilized in patch versions.
// If a "Rust 2.0" is ever released, we'll have to handle that explicitly.
const MSRV_MINOR: u16 = 31;
const CURRENT_MINOR: u16 = 46;
const CURRENT_MINOR: u16 = 47;

fn main() {
let msrv = Version::from_mmp(1, MSRV_MINOR, 0);
Expand Down
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
//! The following methods and constants are available via the prelude:
//!
//! ```rust,ignore
//! // 1.47
//! Range::is_empty
//! Result::as_deref
//! Result::as_deref_mut
//! Vec::leak
//! f32::TAU
//! f64::TAU
//!
//! // 1.46
//! i8::leading_ones
//! i8::trailing_ones
Expand Down Expand Up @@ -540,6 +548,8 @@ mod v1_44;
mod v1_45;
#[cfg(__standback_before_1_46)]
mod v1_46;
#[cfg(__standback_before_1_47)]
mod v1_47;

pub mod prelude {
#[cfg(__standback_before_1_42)]
Expand Down Expand Up @@ -589,6 +599,10 @@ pub mod prelude {
pub use crate::v1_45::int_v1_45;
#[cfg(__standback_before_1_46)]
pub use crate::v1_46::{int_v1_46, Option_v1_46};
#[cfg(all(feature = "std", __standback_before_1_47))]
pub use crate::v1_47::Vec_v1_47;
#[cfg(__standback_before_1_47)]
pub use crate::v1_47::{Range_v1_47, Result_v1_47};
#[cfg(__standback_before_1_39)]
pub use core::unimplemented as todo;
}
Expand Down Expand Up @@ -678,6 +692,11 @@ pub mod f32 {
pub use crate::v1_43::f32::{LOG10_2, LOG2_10};
#[cfg(__standback_since_1_43)]
pub use core::f32::consts::{LOG10_2, LOG2_10};

#[cfg(__standback_before_1_47)]
pub use crate::v1_47::f32::TAU;
#[cfg(__standback_since_1_47)]
pub use core::f32::consts::TAU;
}
}
pub mod f64 {
Expand All @@ -686,6 +705,11 @@ pub mod f64 {
pub use crate::v1_43::f64::{LOG10_2, LOG2_10};
#[cfg(__standback_since_1_43)]
pub use core::f64::consts::{LOG10_2, LOG2_10};

#[cfg(__standback_before_1_47)]
pub use crate::v1_47::f64::TAU;
#[cfg(__standback_since_1_47)]
pub use core::f64::consts::TAU;
}
}
pub mod char {
Expand Down
53 changes: 53 additions & 0 deletions src/v1_47.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::traits::Sealed;
use core::ops::{DerefMut, Range};

pub trait Range_v1_47<Idx>: Sealed<Range<Idx>> {
fn is_empty(&self) -> bool;
}

impl<Idx: PartialOrd<Idx>> Range_v1_47<Idx> for Range<Idx> {
fn is_empty(&self) -> bool {
!(self.start < self.end)
}
}

pub trait Result_v1_47<T: DerefMut, E>: Sealed<Result<T, E>> {
fn as_deref(&self) -> Result<&T::Target, &E>;
fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E>;
}

impl<T: DerefMut, E> Result_v1_47<T, E> for Result<T, E> {
fn as_deref(&self) -> Result<&T::Target, &E> {
self.as_ref().map(|t| t.deref())
}

fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> {
self.as_mut().map(|t| t.deref_mut())
}
}

#[cfg(feature = "std")]
pub trait Vec_v1_47<T>: Sealed<Vec<T>> {
fn leak<'a>(self) -> &'a mut [T]
where
T: 'a;
}

#[cfg(feature = "std")]
impl<T> Vec_v1_47<T> for Vec<T> {
#[inline]
fn leak<'a>(self) -> &'a mut [T]
where
T: 'a,
{
Box::leak(self.into_boxed_slice())
}
}

pub mod f32 {
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;
}

pub mod f64 {
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
}

0 comments on commit 5526774

Please sign in to comment.