Crate enso_prelude[][src]

Expand description

This module re-exports a lot of useful stuff. It is not meant to be used by libraries, but it is definitely usefull for bigger projects. It also defines several aliases and utils which may find their place in new libraries in the future.

Re-exports

pub use paste;
pub use weak_table;

Modules

at_least_one_of_two

Definition of AtLeastOneOfTwo.

fmt

Utilities for formatting and printing Strings.

iter

Composable external iteration.

mem

Basic functions for dealing with memory.

monoid

A class for monoids (types with an associative binary operation that has an identity) with various general-purpose instances.

non_empty_vec

This file contains an implementation of Vec that can’t be empty.

semigroup

In mathematics, a semigroup is an algebraic structure consisting of a set together with an associative binary operation. A semigroup generalizes a monoid in that there might not exist an identity element. It also (originally) generalized a group (a monoid with all inverses) to a type where every element did not have to have an inverse, thus the name semigroup.

slice

A dynamically-sized view into a contiguous sequence, [T].

Macros

Debug

Derive macro generating an impl of the trait Debug.

Hash

Derive macro generating an impl of the trait Hash.

alias
clone_boxed
enclose

Macro for cloning values to close.

f

Clones all arguments from the first argument list by using CloneRef and defines lambda with arguments from the second argument list (if present). For example, the following usage

f_

Variant of the f macro producing a lambda which drops its first argument.

f__

Variant of the f macro producing a lambda which drops its first and second arguments.

ieprint

Print an iformat!-ed string to standard error.

ieprintln

Print an iformat!-ed string to standard error, followed by \n.

iformat

Creates a String by interpolating inlined expressions. Takes one argument, which must be a string literal.

iformat_args

Create a fmt::Arguments value a la format_args! with inlined expressions (using the same syntax as iformat!).

im_string_newtype

Defines a newtype for ImString.

impl_clone_ref_as_clone
impl_clone_ref_as_clone_no_from
impls

Allows for nicer definition of impls, similar to what Haskell or Scala does. Reduces the needed boilerplate. For example, the following usage:

ipanic

Panic with an iformat!-ed message.

iprint

Print an iformat!-ed string to standard out.

iprintln

Print an iformat!-ed string to standard out, followed by \n.

iwrite

Print an iformat!-ed string to the given buffer.

iwriteln

Print an iformat!-ed string to the given buffer, followed by \n.

lazy_static
unreachable_panic

A macro for use in situations where the code is unreachable.

Structs

Anything

Placeholder type used to represent any value type. It is useful to define type-level relations like defining an unit with any quantity, let it be distance or mass.

BTreeMap

A map based on a B-Tree.

Cell

A mutable memory location.

CloneCell
CloneRefCell
CowString

A copy-on-write String implementation. It is a newtype wrapper for Cow<'static,str> and provides many useful impls for efficient workflow. Use it whenever you want to store a string but you are not sure if the string will be allocated or not. This way you can store a static slice as long as you can and switch to allocated String on demand.

DefaultHasher

The default Hasher used by RandomState.

False

Type level false value.

HashMap

A hash map implemented with quadratic probing and SIMD lookup.

HashSet

A hash set implemented as a HashMap where the value is ().

ImString

Immutable string implementation with a fast clone implementation.

Immutable

A zero-overhead newtype which provides immutable access to its content. Of course this does not apply to internal mutability of the wrapped data. A good use case of this structure is when you want to pass an ownership to a structure, allow access all its public fields, but do not allow their modification.

NonEmptyVec

A version of std::vec::Vec that can’t be empty.

PhantomData

Zero-sized type used to mark things that “act like” they own a T.

Range

A (half-open) range bounded inclusively below and exclusively above (start..end).

RangeFrom

A range only bounded inclusively below (start..).

RangeFull

An unbounded range (..).

RangeInclusive

A range bounded inclusively below and above (start..=end).

RangeTo

A range only bounded exclusively above (..end).

RangeToInclusive

A range only bounded inclusively above (..=end).

Rc

A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.

Ref

Wraps a borrowed reference to a value in a RefCell box. A wrapper type for an immutably borrowed value from a RefCell<T>.

RefCell

A mutable memory location with dynamically checked borrow rules

RefMut

A wrapper type for a mutably borrowed value from a RefCell<T>.

SmallVec

A Vec-like container that can store a small number of elements inline.

Switch

The Switch type. Read module docs to learn more.

TraceCopies

An utility for tracing all copies of CloneRef-able entity.

True

Type level true value.

Weak

Weak is a version of Rc that holds a non-owning reference to the managed allocation. The allocation is accessed by calling upgrade on the Weak pointer, which returns an Option<Rc<T>>.

WeakKeyHashMap

A hash map with weak keys, hashed on key value.

WeakValueHashMap

A hash map with weak values.

WithPhantom

A wrapper adding a phantom type to a structure.

Enums

AtLeastOneOfTwo

A struct similar to Option and Either. It can contain the first value, or the second value, or both of them at the same time.

Cow

A clone-on-write smart pointer.

Traits

Add

The addition operator +.

Any

A trait to emulate dynamic typing.

AsOwned

The owned version of a type. It would be super cool if Rust would allow us to automatically implement it for every type: Owned<&T> = T and Owned<T> = T if T was not a reference. Unfortunately, we need to implement it by hand for every type now.

Boolinator

This trait defines a number of combinator-style methods for use with bool values.

CellGetter

Generalization of the Cell::get mechanism. Can be used for anything similar to Cell.

CellProperty

Generalization of modify utilities for structures similar to Cell.

CellSetter

Generalization of the Cell::set mechanism. Can be used for anything similar to Cell.

CloneRef

Clone for internal-mutable structures. This trait can be implemented only if mutating one structure will be reflected in all of its clones. Please note that it does not mean that all the fields needs to provide internal mutability as well. For example, a structure can remember it’s creation time and store it as f32. As long as it cannot be mutated, the structure can implement CloneRef. In order to guide the auto-deriving mechanism, it is advised to wrap all immutable fields in the Immutable newtype.

ClonedRef

Trait for types that can be internally cloned using CloneRef, like Option<&T>.

ContentRef

Unwrapping utility for wrapped types.

Debug

? formatting.

Deref

Used for immutable dereferencing operations, like *v.

DerefMut

Used for mutable dereferencing operations, like in *v = 1;.

Display

Format trait for an empty format, {}.

Div

The division operator /.

Fail

The Fail trait.

FromIterator

Conversion from an Iterator.

HasContent

Trait for any type which wraps other type. See docs of Wrapper to learn more.

HasItem

Type family for structures containing items.

HasRefValue
Hash

A hashable type.

Hasher

A trait for hashing an arbitrary stream of bytes.

Index

Used for indexing operations (container[index]) in immutable contexts.

IndexMut

Used for indexing operations (container[index]) in mutable contexts.

Itertools

An Iterator blanket implementation that provides extra adaptors and methods.

KnownTypeValue

Defines relation between types and values, like between True and true.

Monoid

Mutable Monoid definition.

Mul

The multiplication operator *.

Neg

The unary negation operator -.

Num

The base trait for numeric types, covering 0 and 1 values, comparisons, basic numeric operations, and string conversion.

OptionOps

Adds mapping methods to the Option type.

PartialSemigroup

Mutable Semigroup definition. Impls should satisfy the associativity law: x.concat(y.concat(z)) = x.concat(y).concat(z), in symbolic form: x <> (y <> z) = (x <> y) <> z

PhantomConversions

A utility for easy driving of type-level computations from value level. Often we’ve got some type level relations, like a few singleton types, and for each such type we’ve got an associated value. For example, we can define types Int and Float and associate with them WebGlContext::Int and WebGlContext::Float constants encoded as GlEnum. In order to convert Int or Float to the GlEnum we do not need the instance of the types, only the information what type it was. So we can define:

RangeBounds

RangeBounds is implemented by Rust’s built-in range types, produced by range syntax like .., a.., ..b, ..=c, d..e, or f..=g.

RefCellOptionOps
ResultOps

Adds utilities to the Result type.

ResultUnwrapBoth
Semigroup
SliceIndex

A helper trait used for indexing operations.

SmallVecOps

Adds methods to the SmallVec type.

StringOps
StrongRef

Abstraction for a strong reference like Rc or newtypes over it.

Sub

The subtraction operator -.

ToImpl

Provides method to, which is just like into but allows fo superfish syntax.

ToRef

Similar to AsRef but more specific and automatically implemented for every type. Allows for conversion &T to &T (identity) and T to &T for any type T. In contrast, AsRef requires explicit impls, so for example you cannot do let t:&() = ().as_ref()

TryFrom

Simple and safe type conversions that may fail in a controlled way under some circumstances. It is the reciprocal of TryInto.

TryInto

An attempted conversion that consumes self, which may or may not be expensive.

TypeDisplay

Like Display trait but for types. However, unlike Display it defaults to impl::any::type_name if not provided with explicit implementation.

Unwrap

Unwraps the content by consuming this value.

VecOps
WeakElement

Interface for elements that can be stored in weak hash tables.

WeakKey

Interface for elements that can act as keys in weak hash tables.

WeakOps

Mapping methods to the Weak type.

WeakRef

Abstraction for a weak reference like Weak or newtypes over it.

WithContent

Runs a function on the reference to the content.

Wrap

Wrapping utility for values.

Functions

Immutable

Constructor of the Immutable struct.

backtrace

Print the current backtrace.

content

Provides reference to the content of this value.

default

Alias for Default::default().

identity

The identity function.

type_display

Formats the type for the user-facing output.

type_name

Returns the name of a type as a string slice.

unwrap

Unwrap the content by consuming this value.

with

Surprisingly useful function. Consider the following code:

wrap

Wraps the value and returns the wrapped type.

Type Definitions

Content

Accessor for the wrapped value.

Owned

Owned type family.

PhantomData2

The following PhantomData implementations allow each argument to be non Sized. Unfortunately, this is not equivalent to PhantomData<(T1,T2,...)>, as tuple requires each arg to implement Sized.

PhantomData3
PhantomData4
PhantomData5
PhantomData6
PhantomData7
PhantomData8
PhantomData9
RefValue
TypeValue

Derive Macros

CloneRef

Derives CloneRef implementation for given type. It performs clone_ref on every member field. The input type must implement Clone and its every field must implement CloneRef.

Derivative
Fail
Shrinkwrap

Trait aliases

BiInto

Can be transformed from and into.

HasSizedContent

Trait which enables Sized super-bound on the Content type.

IntoOwned

Converts type to its owned version.

IntoSelfFrom

This is used to make type inference better at use sites - without it, Rust would force one to write the where clause at every use site.

ItemClone
PhantomInto

Like Into but for phantom types.

RefInto

Alias for for<'t> &'t Self : Into<T>.

Str

Abstraction for any kind of string as an argument. Functions defined as fn test<S:Str>(s: Str) { ... } can be called with String, &String, and &str without requiring caller to know the implementation details. Moreover, the definition can decide if it needs allocation or not. Calling s.as_ref() will never allocate, while s.into() will allocate only when necessary.

Wrapper

Trait for objects which wrap values. Please note that this implements safe wrappers, so the object - value relation must be bijective.