core_extensions 0.1.17

This crate provides many extensions to core/std library types.
Documentation

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.

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 [Iterator]s by cloning the one it references,only possible if it is Clone.

IterConstructor: Constructs [Iterator]s 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.