logo

Crate std_x

source · []
Expand description

std_x - Collection of general purpose tools for solving problems. Fundamentally extend the language without spoiling, so may be used solely or in conjunction with another module of such kind.

Module :: std_x

experimental rust-status docs.rs discord

Collection of general purpose tools for solving problems. Fundamentally extend the language without spoiling, so may be used solely or in conjunction with another module of such kind.

Sample :: implements

use std_x::prelude::*;

fn main()
{
  println!( "implements!( 13_i32 => Copy ) : {}", implements!( 13_i32 => Copy ) );
  println!( "implements!( Box::new( 13_i32 ) => Copy ) : {}", implements!( Box::new( 13_i32 ) => Copy ) );
}

Sample :: type constructors

In Rust, you often need to wrap a given type into a new one. The role of the orphan rules in particular is basically to prevent you from implementing external traits for external types. To overcome the restriction developer usually wrap the external type into a tuple introducing a new type. Type constructor does exactly that and auto-implement traits From, Into, Deref and few more for the constructed type.

Macro types is responsible for generating code for Single, Pair, Homopair, Many. Each type constructor has its own keyword for that, but Pair and Homopair use the same keyword difference in a number of constituent types. It is possible to define all types at once.

use std_x::prelude::*;

types!
{

  single MySingle : f32;
  single SingleWithParametrized : std::sync::Arc< T : Copy >;
  single SingleWithParameter : < T >;

  pair MyPair : f32;
  pair PairWithParametrized : std::sync::Arc< T1 : Copy >, std::sync::Arc< T2 : Copy >;
  pair PairWithParameter : < T1, T2 >;

  pair MyHomoPair : f32;
  pair HomoPairWithParametrized : std::sync::Arc< T : Copy >;
  pair HomoPairWithParameter : < T >;

  many MyMany : f32;
  many ManyWithParametrized : std::sync::Arc< T : Copy >;
  many ManyWithParameter : < T >;

}

Sample :: make - variadic constructor

Implement traits Make0, Make1 up to MakeN to provide the interface to construct your structure with a different set of arguments. In this example structure, Struct1 could be constructed either without arguments, with a single argument, or with two arguments.

  • Constructor without arguments fills fields with zero.
  • Constructor with a single argument sets both fields to the value of the argument.
  • Constructor with 2 arguments set individual values of each field.
use std_x::prelude::*;

#[ derive( Debug, PartialEq ) ]
struct Struct1
{
  a : i32,
  b : i32,
}

impl Make0 for Struct1
{
  fn make_0() -> Self
  {
    Self { a : 0, b : 0 }
  }
}

impl Make1< i32 > for Struct1
{
  fn make_1( val : i32 ) -> Self
  {
    Self { a : val, b : val }
  }
}

impl Make2< i32, i32 > for Struct1
{
  fn make_2( val1 : i32, val2 : i32 ) -> Self
  {
    Self { a : val1, b : val2 }
  }
}

let got : Struct1 = make!();
let exp = Struct1{ a : 0, b : 0 };
assert_eq!( got, exp );

let got : Struct1 = make!( 13 );
let exp = Struct1{ a : 13, b : 13 };
assert_eq!( got, exp );

let got : Struct1 = make!( 1, 3 );
let exp = Struct1{ a : 1, b : 3 };
assert_eq!( got, exp );

To add to your project

cargo add std_x

Modules

Dependencies.

Exposed namespace of the module.

Orphan namespace of the module.

Prelude to use essentials: use my_module::prelude::*.

Protected namespace of the module.

Macros

Function-like macro to generate options adapter and its implementation for structure option.

Generate code only if feature::make is enabled.

Internal impls1 macro. Don’t use.

Type constructor of many.

Pair type constructor.

Type constructor of single.

Alias of Vec for internal usage.

Asserts that two expressions are identical to each other.

Asserts that two expressions are not identical to each other.

Asserts that a boolean expression is true at runtime.

Asserts that two expressions are equal to each other (using PartialEq).

Asserts that two expressions are not equal to each other (using PartialEq).

Asserts that a boolean expression is true at runtime.

Literally just a BTreeMap literal with keys and values into’d.

Unwrap braces of token tree and pass its content to the passed callback. If token tree in not braced then it passed to callback as is.

Literally just a BTreeSet literal with values into’d.

Chain zero or more iterators together into one sequence.

Compile-time assertion that two values have the same size.

Compile-time assertion that memory behind two references have the same size.

Macro to compare meta condition is true at compile-time.

Compile-time assertion of having the same align.

Compile-time assertion that two types have the same size.

Get name of a function.

Macro to rename function.

Split functions.

Split functions.

Module :: for_each

Literally just a BinaryHeap literal with values into’d.

Literally just a HashMap literal with keys and values into’d.

Literally just a HashSet literal with values into’d.

Macro which returns its input as is.

Macro implements to answer the question: does it implement a trait?

Define implementation putting each function under a macro.

Define implementation putting each function under a macro.

Define implementation putting each function under a macro.

Macros to put each function under a named macro to index every function in a class.

Index of items.

Macro to inspect type of a variable and its size exporting it as a string.

Macro to inspect type of a variable and its size printing into stdout and exporting it as a string.

Macro instance_of to answer the question: does it implement a trait? Alias of the macro implements.

Macro to answer the question: is it a slice?

Literally just a LinkedList literal with values into’d.

Variadic constructor.

Protocol of modularity unifying interface of a module.

Define implementation putting each function under a macro and adding attribute #[ test ].

Define implementation putting each function under a macro and adding attribute #[ test ].

Index of items.

Type constructor to define tuple wrapping a given type.

Literally just a VecDeque literal with values into’d.

Structs

An ordered map based on a B-Tree.

An ordered set based on a B-Tree.

baic implementation of generic BasicError

A priority queue implemented with a binary heap.

A contiguous growable array type, written as Vec<T>, short for ‘vector’.

A hash map implemented with quadratic probing and SIMD lookup.

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

Type constructor to wrap pair of the same type.

Alternative implementation of interval.

A doubly-linked list with owned nodes.

Type constructor to wrap a vector.

A hash map implemented with quadratic probing and SIMD lookup.

Type constructor to wrap two types into a tuple.

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

Type constructor to wrap a another type into a tuple.

A contiguous growable array type, written as Vec<T>, short for ‘vector’.

A double-ended queue implemented with a growable ring buffer.

A contiguous growable array type, written as Vec<T>, short for ‘vector’.

Enums

A type returned by the diff_with function.

The enum Either with variants Left and Right is a general purpose sum type with two cases.

Value that either holds a single A or B, or both.

An enum used for controlling the execution of fold_while.

MinMaxResult is an enum returned by minmax.

A value yielded by WithPosition. Indicates the position of this element in the iterator results.

Traits

Reinterpret as array.

Reinterpret as slice.

Reinterpret as tuple.

Clone as array.

Clone as tuple.

Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>.

Interval adapter. Interface to interval-like structures.

Adapter for IsolateOptions.

An Iterator blanket implementation that provides extra adaptors and methods.

Constructor without arguments.

Constructor with single argument.

Constructor with two arguments.

Constructor with three arguments.

Adapter for ParseOptions.

An iterator that allows peeking at an element before deciding to accept it.

Adapter for Split Options.

Implementation of trait From to vectorize into/from.

Implementation of trait Into to vectorize into/from.

Functions

Clone boxed dyn.

Test whether the predicate holds for all elements in the iterable.

Test whether the predicate holds for any elements in the iterable.

Assert that two iterables produce equal sequences, with the same semantics as equal(a, b).

Create an iterator that first iterates i and then j.

Create an iterator that clones each element from &T to T

Combine all an iterator’s elements into one element by using Extend.

Create an iterator that maps for example iterators of ((A, B), C) to (A, B, C).

Compares every element yielded by both i and j with the given function in lock-step and returns a Diff which describes how j differs from i.

Iterate iterable with a running index.

Return true if both iterables produce equal sequences (elements pairwise equal and sequences of the same length), false otherwise.

Perform a fold operation over the iterable.

Create an iterator that interleaves elements in i and j.

Iterate iterable with a particular value inserted between each element.

Iterate iterable with a particular value created by a function inserted between each element.

Creates a new iterator that infinitely applies function to value and yields results.

Combine all iterator elements into one String, seperated by sep.

Create an iterator that merges elements of the contained iterators using the ordering function.

Create an iterator that merges elements of the contained iterators.

Return the maximum value of the iterable.

Create an iterator that merges elements in i and j.

Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.

Return the minimum value of the iterable.

An iterator adaptor that allows the user to peek at multiple .next() values without advancing the base iterator.

Converts an iterator of tuples into a tuple of containers.

An iterator that generalizes .zip() and allows running multiple iterators in lockstep.

Get current time. Units are milliseconds.

Partition a sequence using predicate pred so that elements that map to true are placed before elements which map to false.

A drop-in replacement for std::iter::Peekable which adds a peek_nth method allowing the user to peek at a value several iterations forward without advancing the base iterator.

“Lift” a function of the values of an iterator so that it can process an iterator of Result values instead.

Create an iterator where you can put back a single item

Create an iterator where you can put back multiple values to the front of the iteration.

Return an iterator inside a Rc<RefCell<_>> wrapper.

Create an iterator that produces n repetitions of element.

Iterate iterable in reverse.

Sort all iterator elements into a new iterator in ascending order.

Creates a new unfold source with the specified closure as the “iterator function” and an initial state to eventually pass to the closure

Iterate i and j in lock step.

Iterate i and j in lock step.

Attribute Macros

Derive macro to generate former for a structure. Former is variation of Builder Pattern.

Derive Macros

Derive macro to generate former for a structure. Former is variation of Builder Pattern.