no-std core_extensions

Extensions for core/std library types, and other miscelaneous features

29 releases (9 stable)

Uses old Rust 2015

1.4.1 May 22, 2021
1.3.2 Apr 17, 2021
0.1.20 Jan 8, 2021
0.1.18 Oct 22, 2020
0.1.4 Oct 6, 2018

#7 in No standard library

Download history 194/week @ 2021-04-08 202/week @ 2021-04-15 81/week @ 2021-04-22 103/week @ 2021-04-29 102/week @ 2021-05-06 481/week @ 2021-05-13 631/week @ 2021-05-20 694/week @ 2021-05-27 802/week @ 2021-06-03 829/week @ 2021-06-10 478/week @ 2021-06-17 423/week @ 2021-06-24 429/week @ 2021-07-01 660/week @ 2021-07-08 486/week @ 2021-07-15 256/week @ 2021-07-22

643 downloads per month
Used in 21 crates (12 directly)


6.5K SLoC

Rust crates.io api-docs

Extension traits for many standard/core library types/traits. and other miscelaneuous types / traits / functions / macros.

Adding as dependency

This crate requires cargo features for enabling items, to get all of them you can use:

version = "1.0"
features = ["std", "all_items"]

The "std" feature is required to enable impls and items that use std types, otherwise only the core library is supported.

For enabling features individually, look here.

This crate currently requires cargo features to use newer language features,


Showcasing some features from this crate.

quasiconst, generic constants.

The quasiconst macro allows emulating generic constants by generating a zero-sized generic type that implements the ConstVal trait, the preferred way to get its value is the getconst macro.

This example demonstrates how you can use them to declare a generic VTABLE constant.

use core_extensions::{getconst, quasiconst};

use std::fmt::{self, Debug};

    pub const VTABLE<T: Debug>: &'static Vtable = &Vtable {
        size: std::mem::size_of::<T>(),
        align: std::mem::align_of::<T>(),
        drop: drop_erased::<T>,
        fmt: debug_fmt_erased::<T>,

fn main() {
    const VTABLE_U8: &'static Vtable = getconst!(VTABLE<u8>);
    assert_eq!(VTABLE_U8.size, 1);
    assert_eq!(VTABLE_U8.align, 1);

    const VTABLE_USIZE: &'static Vtable = getconst!(VTABLE<usize>);
    assert_eq!(VTABLE_USIZE.size, std::mem::size_of::<usize>());
    assert_eq!(VTABLE_USIZE.align, std::mem::align_of::<usize>());

    const VTABLE_STRING: &'static Vtable = getconst!(VTABLE<&str>);
    assert_eq!(VTABLE_STRING.size, std::mem::size_of::<usize>() * 2);
    assert_eq!(VTABLE_STRING.align, std::mem::align_of::<usize>());

pub struct Vtable {
    pub size: usize,
    pub align: usize,
    pub drop: unsafe fn(*mut ()),
    pub fmt: unsafe fn(*const (), &mut fmt::Formatter<'_>) -> fmt::Result,

unsafe fn drop_erased<T>(ptr: *mut ()) {
    std::ptr::drop_in_place(ptr as *mut T)

unsafe fn debug_fmt_erased<T>(ptr: *const (), f: &mut fmt::Formatter<'_>) -> fmt::Result 
    T: Debug,
    let this = unsafe{ &*(ptr as *const T) };
    Debug::fmt(this, f)

no-std support

This crate works in #![no_std] contexts by default.

Supported Rust versions

This crate support Rust back to 1.41.0, requiring cargo features to use language features from newer versions.

Cargo Features

crate features

The "all_items" feature enables all of these features, you can use it instead of the ones below if you don't mind longer compile-times:

Rust Version numbers

These features enable code that require some Rust version past the minimum supported one:

  • "rust_1_46": Makes TransparentNewtype and TypeIdentity associated functions that take Rc<Self> or Arc<Self> callable as methods.

  • "rust_1_51": Enables the "rust_1_46" feature, and impls of traits for all array lengths.

Support for other crates

All of these are disabled by default:

  • "std": Enables std library support. Implies the "alloc" feature.

  • "alloc": Enables alloc library support.

  • "serde_": Enables serde support.

Miscelaneous features

"track_caller": Enables the "rust_1_46" feature. Changes ResultLike to allow getting the caller location in ResultLike::into_result_, and makes IsNoneError store where it was constructed.

"docsrs": Used to document the required features in docs.rs, requires Rust nightly. Doesn't enable any items itself.


core_extensions is licensed under either of

Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in core_extensions by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.