[][src]Crate core_extensions

This crate provides:

  • Extension traits for many standard/core library types/traits.

  • SelfOps:to extend all types with generic operations.

  • Type-level representations of bool and unsafe .

  • Marker traits to encode invariants about types.

  • etc.

no-std support

To use this crate in no_std contexts disable the default-feature.

Supported Rust versions

This crate support Rust back to 1.20, using a build script to automatically enable features from newer versions.

Cargo Features

"std": Enables standard library support.Enabled by default.

"serde_": Enables serde support.Disabled by default.

"typenum": Enables trait impls for typenum types.Disabled by default.

"colltraits": Enables trait impls for the collection traits in the collection_traits module.

"const_generics": Enables impls of traits for all array lengths, requires versions of Rust where const generics are stable.

"nightly_const_generics": Enables impls of traits for all array lengths in Rust nightly versions prior to the stabilization of const generics.

Contents

Extension trait:SelfOps

This is implemented for all types.

The most importand methods in this are:

  • piped: Allows emulating the pipeline operator.

  • mutated: Allows mutating self with a closure passing it along the method chain

  • observe: Observes the value of self with a closure passing it along the method chain unmodified.

  • into_, as_ref_, as_mut_: Alternative syntax for the standard conversion methods.

Other extension traits

ResultExt::Extension trait for Result.

OptionExt::Extension trait for Option.

BoolExt:Extension trait for bool.

IntegerExt:Extension trait for integers.

ToTime:Extension trait for integers, to create Durations of a certain unit.

StringExtExtension trait for str.

Construction traits

MarkerType: Represents a zero-sized marker type.

ConstDefault: A const-equivalent of the Default trait.

Other traits

ResultLike: Trait for types with item/error values,like Option and Result.

TransparentNewtype Represents a newtype that is safe to transmute to and/from its only non-zero-sized field.

Iteration

IteratorExt Extension trait for Iterator implementors.

Factories

IterCloner: Constructs Iterators by cloning the one it references,only possible if it is Clone.

IterConstructor: Constructs Iterators using a closure,this can be done multiple times if the closure it Copy.

Iterators

Loop: Iterator that infinitely produces a value by calling an impl FnMut()->T

LazyOnce: Lazy version of [::std::iter::Once],only evaluating the item when Iterator::next is called.

Type-level stuff

Type-Level bool

This crate contains types and operations using type-level bools.

Boolean: Trait representing bool.

True/ False: Types representing true/false.

Type equality

TypeIdentity Allows converting a type back to itself.Useful in generic contexts.

Empty type

Void: Uninstantiable Type for statically impossible situations. Useful as a type parameter/associated type.

(Un)safety represented as type

maybe_unsafe emulates a safe/unsafe effect using types.

Allows having traits whose implementations can choose whether their methods/functions are safe to call or not.

Re-exports

pub use self::callable::CallInto;
pub use self::callable::CallMut;
pub use self::callable::CallRef;
pub use self::strings::StringExt;
pub use self::bool_extensions::BoolExt;
pub use self::integer_extensions::IntegerExt;
pub use self::integer_extensions::ToTime;
pub use self::iterators::IterCloner;
pub use self::iterators::IterConstructor;
pub use self::iterators::IteratorExt;
pub use self::iterators::LazyOnce;
pub use self::phantom_variances::InvariantPhantom;
pub use self::phantom_variances::InvariantRefPhantom;
pub use self::phantom_variances::VariantDropPhantom;
pub use self::phantom_variances::VariantPhantom;
pub use self::transparent_newtype::TransparentNewtype;
pub use self::try_from::TryFrom;
pub use self::try_from::TryInto;
pub use self::void::Void;

Modules

bool_extensions

Extension traits for bool.

callable

Contains implementable alternatives of the standard Fn/FnMut/FnOnce traits.

collection_traits

Extension traits implemented for multiple types

integer_extensions

Extension traits for integers and types used in the traits.

iterators

Iterator adaptors and constructors.

macros

A variety of macros.

marker_traits

Contains marker traits representing a variety of guarantees provided by the implementors.

maybe_unsafe

Allows defining traits whose functions/methods can be safe/unsafe to call depending on the implementor.

measure_time

Time measurement,including functions and types.

option_result_ext

Contains [extension] traits for Option and Result

phantom_variances

Contains many type aliases for PhantomData with different lifetime variances.

prelude

The items from this crate which are almost always used.

slices

Slice extensions.

strings

Extension trait for string types.

transparent_newtype

Contains the TransparentNewtype trait to enable safer transmutation between types.

try_from

A version of TryFrom/TryInto in stable Rust before they are stabilized. These traits are used for fallible conversions.

type_asserts

Assertions done on the type-level,mostly for tests.

type_level_bool

Module containing definitions and operations for type level booleans

utils

Miscelaneous utility functions

void

Contains types and functions for impossible situations.

Macros

callable_impl

This macro allows more ergonomically implementing the Call(Ref|Mut|Into) traits .

const_default

Gets the ConstDefault::DEFAULT associated constant for This.

iter_cloner

Use this macro to create an IterCloner from an Iterator value.

matches

Macro that evaluates to true if the expression matches any of the patterns (this macro can have multiple patterns).

unsafe_

Macro for correctly using unsafe{} blocks inside functions that take IsUnsafe references.

Traits

ConstDefault

A const equivalent of the Default trait.

MarkerType

Represents a zero-sized marker type .

OptionExt

Extension trait for Option.

ResultExt

Extension trait for Result.

ResultLike

Trait for types with error and item values.

SelfOps

Extension trait for every type.

SliceExt

Extension trait for [T] and str.

TypeIdentity

Allows converting Self to Self::Type by proving that both types are equal.

TypePanic

A trait used to cause a compile-time error mentioning the types constrained by it.

ValSliceExt

Extension trait for [T].

Type Definitions

TIdentity

A type-level identity function