Skip to content

Commit

Permalink
Reduce MSRV to 1.60
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Oct 5, 2024
1 parent 0293642 commit fffa1fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
toolchain: [stable, beta, nightly]
toolchain: ['1.60', stable, beta, nightly]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "constcat"
version = "0.5.0"
authors = ["Ross MacArthur <ross@macarthur.io>"]
edition = "2018"
rust-version = "1.60"
description = "concat! with support for const variables and expressions"
readme = "README.md"
repository = "https://github.com/rossmacarthur/constcat"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const SECONDARIES: &'static [(u8, u8, u8)] = &[(255, 255, 0), (255, 0, 255), (0,
const COLORS: &[(u8, u8, u8)] = concat_slices!([(u8, u8, u8)]: PRIMARIES, SECONDARIES);
```

### MSRV

This crate supports Rust 1.60 and above.

[`std::concat!`]: core::concat

## License
Expand Down
20 changes: 16 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
//!
//! [`std::concat!`]: core::concat
//! [`std::concat_bytes!`]: core::concat_bytes
//!
//! ## MSRV
//!
//! This crate supports Rust 1.60 and above.
#![no_std]

Expand Down Expand Up @@ -113,6 +117,7 @@ macro_rules! _concat {
}};

(@impl $($s:expr),+) => {{
use $crate::core::primitive::{str, u8};
$(
const _: &str = $s; // require str constants
)*
Expand Down Expand Up @@ -184,6 +189,7 @@ macro_rules! _concat_bytes {
}};

(@impl $($s:expr),+) => {{
use $crate::core::primitive::u8;
$crate::concat_slices!([u8]: $($s),+)
}};
}
Expand Down Expand Up @@ -241,7 +247,6 @@ macro_rules! concat_slices {
$crate::_concat_slices!([$T]: $($s),*)
};
}

#[doc(hidden)]
#[macro_export]
macro_rules! _concat_slices {
Expand All @@ -251,13 +256,20 @@ macro_rules! _concat_slices {
}};

([$T:ty]: $($s:expr),+) => {{
use $crate::core::mem::MaybeUninit;
use $crate::core::primitive::{u8, usize};
use $crate::core::mem;
$(
const _: &[$T] = $s; // require constants
)*
const TSIZE: usize = mem::size_of::<$T>();
union TypeAsBytes<X: Copy> { bytes: [u8; TSIZE], inner: MaybeUninit<X> }
const ZERO: TypeAsBytes<$T> = TypeAsBytes { bytes: [0; TSIZE] };
const LEN: usize = $( $s.len() + )* 0;
const ARR: [$T; LEN] = {
use $crate::core::mem::MaybeUninit;
let mut arr: [MaybeUninit<$T>; LEN] = [MaybeUninit::zeroed(); LEN];
// Ideally we should use MaybeUninit::zeroed() but we want to
// support older versions of Rust.
let mut arr: [MaybeUninit<$T>; LEN] = [ unsafe { ZERO.inner }; LEN];
let mut base: usize = 0;
$({
let mut i = 0;
Expand Down Expand Up @@ -288,7 +300,7 @@ macro_rules! _concat_slices {
//
// See for more information:
// https://doc.rust-lang.org/core/mem/union.MaybeUninit.html#initializing-an-array-element-by-element
unsafe { $crate::core::mem::transmute(arr) }
unsafe { mem::transmute(arr) }
};
&ARR
}};
Expand Down

0 comments on commit fffa1fb

Please sign in to comment.