1 Commits

Author SHA1 Message Date
javalsai 184b9618b3 feat: no_std environments 2026-05-31 00:30:03 +02:00
5 changed files with 33 additions and 11 deletions
Generated
+1 -1
View File
@@ -4,4 +4,4 @@ version = 4
[[package]] [[package]]
name = "boilerext" name = "boilerext"
version = "0.1.0" version = "0.1.1"
+3 -2
View File
@@ -1,7 +1,7 @@
[package] [package]
name = "boilerext" name = "boilerext"
description = "Rlib with useful boilerplate extension traits for QoL" description = "Rlib with useful boilerplate extension traits for QoL"
version = "0.1.0" version = "0.1.1"
edition = "2024" edition = "2024"
license = "MIT" license = "MIT"
repository = "https://git.javalsai.tuxcord.net/rust/boilerext" repository = "https://git.javalsai.tuxcord.net/rust/boilerext"
@@ -9,7 +9,8 @@ keywords = ["ext", "trait", "extension-trait"]
categories = ["rust-patterns"] categories = ["rust-patterns"]
[features] [features]
default = [] default = ["std"]
std = []
[lints.clippy] [lints.clippy]
cargo = { level = "warn", priority = -1 } cargo = { level = "warn", priority = -1 }
+8
View File
@@ -2,6 +2,8 @@
Rlib with useful boilerplate extension traits for QoL. Rlib with useful boilerplate extension traits for QoL.
Support for `no_std` environments with most extensions preserved.
Aims to extend methods that have negligible performance cost, which only Aims to extend methods that have negligible performance cost, which only
reasonable barrier is their lenthyness or unintuitiveness. reasonable barrier is their lenthyness or unintuitiveness.
@@ -14,6 +16,12 @@ wasn't there.
Documentation is not hosted publicly for now, clone and run `cargo doc` to Documentation is not hosted publicly for now, clone and run `cargo doc` to
generate it. generate it.
# Installation
```sh
cargo add --git https://git.javalsai.tuxcord.net/rust/boilerext
```
# Development # Development
This project uses cargo test/miri test/doc/fmt/check/clippy, codespell, prettier This project uses cargo test/miri test/doc/fmt/check/clippy, codespell, prettier
+4
View File
@@ -20,8 +20,11 @@ errprint() {
set -x set -x
cargo check -q cargo check -q
cargo check -q --no-default-features
cargo clippy -q cargo clippy -q
cargo clippy -q --no-default-features
cargo test -q cargo test -q
cargo test -q --no-default-features
cargo doc -q cargo doc -q
cargo fmt --check cargo fmt --check
codespell codespell
@@ -33,4 +36,5 @@ if [ "${1:-}" == "extra" ]; then (
set -x set -x
cargo +nightly miri test -q cargo +nightly miri test -q
cargo +nightly miri test -q --no-default-features
) fi ) fi
+17 -8
View File
@@ -1,4 +1,8 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
#![no_std]
#[cfg(feature = "std")]
extern crate std;
pub mod prelude { pub mod prelude {
//! Prelude with extended method names that should never collide. //! Prelude with extended method names that should never collide.
@@ -6,7 +10,7 @@ pub mod prelude {
//! Trait identifiers are not exported, only the implementation methods are. //! Trait identifiers are not exported, only the implementation methods are.
//! //!
//! ``` //! ```
//! # use std::ffi::CStr; //! # use core::ffi::CStr;
//! use boilerext::prelude::*; //! use boilerext::prelude::*;
//! CStr::split_ch; //! CStr::split_ch;
//! ``` //! ```
@@ -19,6 +23,7 @@ pub mod prelude {
pub use crate::{cstr::CStrSplit as _, slice::RotateInsertExt as _, slice::SplitOn as _}; pub use crate::{cstr::CStrSplit as _, slice::RotateInsertExt as _, slice::SplitOn as _};
} }
#[cfg(feature = "std")]
pub mod unix_prelude { pub mod unix_prelude {
//! Analogous to [`crate::prelude`] but only for traits exclusive to unix-based systems. //! Analogous to [`crate::prelude`] but only for traits exclusive to unix-based systems.
@@ -26,7 +31,7 @@ pub mod unix_prelude {
} }
pub mod slice { pub mod slice {
use std::borrow::Borrow; use core::borrow::Borrow;
/// Rotates the slice like `rotate_right` while inserting a given value and returning the /// Rotates the slice like `rotate_right` while inserting a given value and returning the
/// popped-off elements. /// popped-off elements.
@@ -79,7 +84,7 @@ pub mod slice {
// swaps `insert` with the rotated part of `self` such that `insert` also becomes the // swaps `insert` with the rotated part of `self` such that `insert` also becomes the
// return slice // return slice
for idx in 0..N { for idx in 0..N {
std::mem::swap(&mut self[idx], &mut insert[idx]); core::mem::swap(&mut self[idx], &mut insert[idx]);
} }
Some(insert) Some(insert)
@@ -139,18 +144,19 @@ pub mod slice {
} }
pub mod cstr { pub mod cstr {
use std::{ use core::{ffi::CStr, num::NonZeroU8};
ffi::{CStr, OsStr}, #[cfg(feature = "std")]
num::NonZeroU8, use std::ffi::OsStr;
};
use crate::slice::SplitOn; use crate::slice::SplitOn;
/// Implements transparent `as_*` methods for unix systems. /// Implements transparent `as_*` methods for unix systems.
#[cfg(feature = "std")]
pub trait UnixCStrAs { pub trait UnixCStrAs {
fn as_os_str(&self) -> &OsStr; fn as_os_str(&self) -> &OsStr;
} }
#[cfg(feature = "std")]
impl UnixCStrAs for CStr { impl UnixCStrAs for CStr {
fn as_os_str(&self) -> &OsStr { fn as_os_str(&self) -> &OsStr {
use std::os::unix::ffi::OsStrExt as _; use std::os::unix::ffi::OsStrExt as _;
@@ -163,7 +169,7 @@ pub mod cstr {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # use std::num::NonZeroU8; /// # use core::num::NonZeroU8;
/// # use boilerext::cstr::CStrSplit; /// # use boilerext::cstr::CStrSplit;
/// let string = c"abcde"; /// let string = c"abcde";
/// ///
@@ -189,13 +195,16 @@ pub mod cstr {
} }
pub mod str { pub mod str {
#[cfg(feature = "std")]
use std::ffi::OsStr; use std::ffi::OsStr;
/// Implements transparent `as_*` methods for unix systems. /// Implements transparent `as_*` methods for unix systems.
#[cfg(feature = "std")]
pub trait UnixStrAs { pub trait UnixStrAs {
fn as_os_str(&self) -> &OsStr; fn as_os_str(&self) -> &OsStr;
} }
#[cfg(feature = "std")]
impl UnixStrAs for str { impl UnixStrAs for str {
fn as_os_str(&self) -> &OsStr { fn as_os_str(&self) -> &OsStr {
use std::os::unix::ffi::OsStrExt as _; use std::os::unix::ffi::OsStrExt as _;