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

Import CStr from core, raise MSRV to 1.64.0 #55

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
- name: Install Rust toolchain
uses: artichoke/setup-rust/build-and-test@v1
with:
toolchain: "1.59.0"
toolchain: "1.64.0"

- name: Compile
run: cargo build --verbose
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.5.0"
authors = ["Ryan Lopopolo <[email protected]>"]
license = "MIT"
edition = "2021"
rust-version = "1.64.0"
readme = "README.md"
repository = "https://github.com/artichoke/qed"
documentation = "https://docs.rs/qed"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ qed::const_assert_matches!(NonZeroU8::new(42), Some(nz) if nz.get() == 42);

## `no_std`

qed is `no_std` compatible although some macros may construct types which
require `::std` to be available.
qed is `no_std` compatible and all macros only require [`core`].

[`core`]: https://doc.rust-lang.org/stable/core/

### Minimum Supported Rust Version

This crate requires at least Rust 1.59.0. This version can be bumped in minor
This crate requires at least Rust 1.64.0. This version can be bumped in minor
releases.

## License
Expand Down
27 changes: 12 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
#![no_std]
#![doc(html_root_url = "https://docs.rs/qed/1.5.0")]

#[cfg(any(test, doc))]
extern crate std;

// Ensure code blocks in `README.md` compile
#[cfg(all(doctest, any(target_pointer_width = "32", target_pointer_width = "64")))]
#[doc = include_str!("../README.md")]
Expand Down Expand Up @@ -286,15 +283,15 @@ macro_rules! const_assert_bytes_has_no_nul {
/// that the given bytes are a valid `CStr` (NUL terminated with no interior NUL
/// bytes).
///
/// [`CStr`]: std::ffi::CStr
/// [`CStr`]: core::ffi::CStr
///
/// This macro emits a compile error if the given slice contains any interior
/// NUL bytes or does not have a NUL terminator.
///
/// # Examples
///
/// ```
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const ARRAY_CLASS: &[u8] = b"Array\0";
/// const ARRAY_CLASS_CSTR: &CStr = qed::const_cstr_from_bytes!(ARRAY_CLASS);
Expand All @@ -304,7 +301,7 @@ macro_rules! const_assert_bytes_has_no_nul {
/// NUL byte:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const BYTES: &[u8] = b"abc\0xyz";
/// const BYTES_CSTR: &CStr = qed::const_cstr_from_bytes!(BYTES);
Expand All @@ -314,7 +311,7 @@ macro_rules! const_assert_bytes_has_no_nul {
/// terminator:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const BYTES: &[u8] = b"Q.E.D.";
/// const BYTES_CSTR: &CStr = qed::const_cstr_from_bytes!(BYTES);
Expand All @@ -324,7 +321,7 @@ macro_rules! const_assert_bytes_has_no_nul {
/// `CStr`:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const EMPTY: &[u8] = b"";
/// const CSTR: &CStr = qed::const_cstr_from_bytes!(BYTES);
Expand All @@ -346,23 +343,23 @@ macro_rules! const_cstr_from_bytes {
// which meets the safety criteria for `CStr::from_bytes_with_nul_unchecked`.
//
// https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.from_bytes_with_nul_unchecked
unsafe { ::std::ffi::CStr::from_bytes_with_nul_unchecked($bytes) }
unsafe { ::core::ffi::CStr::from_bytes_with_nul_unchecked($bytes) }
}};
}

/// Construct a const [`CStr`] from the given `str` at compile time and assert
/// that the given `str` bytes are a valid `CStr` (NUL terminated with no
/// interior NUL bytes).
///
/// [`CStr`]: std::ffi::CStr
/// [`CStr`]: core::ffi::CStr
///
/// This macro emits a compile error if the given `str` contains any interior
/// NUL bytes or does not have a NUL terminator.
///
/// # Examples
///
/// ```
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const ARRAY_CLASS_CSTR: &CStr = qed::const_cstr_from_str!("Array\0");
/// ```
Expand All @@ -371,7 +368,7 @@ macro_rules! const_cstr_from_bytes {
/// NUL byte:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const CSTR: &CStr = qed::const_cstr_from_str!("abc\0xyz");
/// ```
Expand All @@ -380,7 +377,7 @@ macro_rules! const_cstr_from_bytes {
/// terminator:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const CSTR: &CStr = qed::const_cstr_from_str!("Q.E.D.");
/// ```
Expand All @@ -389,7 +386,7 @@ macro_rules! const_cstr_from_bytes {
/// `CStr`:
///
/// ```compile_fail
/// use std::ffi::CStr;
/// use core::ffi::CStr;
///
/// const CSTR: &CStr = qed::const_cstr_from_str!("");
/// ```
Expand All @@ -404,8 +401,8 @@ macro_rules! const_cstr_from_str {

#[cfg(test)]
mod tests {
use ::core::ffi::CStr;
use ::core::num::NonZeroU8;
use ::std::ffi::CStr;

mod core {}
mod std {}
Expand Down