Crate non_std

Source
Expand description

non_std - 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 :: non_std

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 non_std::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 non_std::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 non_std::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 non_std

Modules§

dependency
Dependencies.
exposed
Exposed namespace of the module.
orphan
Orphan namespace of the module.
prelude
Prelude to use essentials: use my_module::prelude::*.
protected
Protected namespace of the module.

Macros§

Options
Function-like macro to generate options adapter and its implementation for structure option.
_if_make
Generate code only if feature::make is enabled.
_impls_callback
Internal impls1 macro. Don’t use.
_many
Type constructor of many.
_pair
Pair type constructor.
_single
Type constructor of single.
_vec
Alias of Vec for internal usage.
a_dbg_id
Asserts that two expressions are identical to each other.
a_dbg_not_id
Asserts that two expressions are not identical to each other.
a_dbg_true
Asserts that a boolean expression is true at runtime.
a_id
Asserts that two expressions are equal to each other (using PartialEq).
a_not_id
Asserts that two expressions are not equal to each other (using PartialEq).
a_true
Asserts that a boolean expression is true at runtime.
bmap
Literally just a BTreeMap literal with keys and values into’d.
braces_unwrap
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.
bset
Literally just a BTreeSet literal with values into’d.
chain
Chain zero or more iterators together into one sequence.
cta_mem_same_size
Compile-time assertion that two values have the same size.
cta_ptr_same_size
Compile-time assertion that memory behind two references have the same size.
cta_true
Macro to compare meta condition is true at compile-time.
cta_type_same_align
Compile-time assertion of having the same align.
cta_type_same_size
Compile-time assertion that two types have the same size.
fn_name
Get name of a function.
fn_rename
Macro to rename function.
fns
Split functions.
fns2
Split functions.
for_each
Module :: for_each
heap
Literally just a BinaryHeap literal with values into’d.
hmap
Literally just a HashMap literal with keys and values into’d.
hset
Literally just a HashSet literal with values into’d.
identity
Macro which returns its input as is.
idents_concat
implements
Macro implements to answer the question: does it implement a trait?
impls
Define implementation putting each function under a macro.
impls1
Define implementation putting each function under a macro.
impls2
Define implementation putting each function under a macro.
impls3
Macros to put each function under a named macro to index every function in a class.
index
Index of items.
inspect_to_str_type_of
Macro to inspect type of a variable and its size exporting it as a string.
inspect_type_of
Macro to inspect type of a variable and its size printing into stdout and exporting it as a string.
instance_of
Macro instance_of to answer the question: does it implement a trait? Alias of the macro implements.
is_slice
Macro to answer the question: is it a slice?
list
Literally just a LinkedList literal with values into’d.
make
Variadic constructor.
mod_interface
Protocol of modularity unifying interface of a module and introducing layers.
tests_impls
Define implementation putting each function under a macro and adding attribute #[ test ].
tests_impls_optional
Define implementation putting each function under a macro and adding attribute #[ test ].
tests_index
Index of items.
types
Type constructor to define tuple wrapping a given type.
vecd
Literally just a VecDeque literal with values into’d.

Structs§

BTreeMap
An ordered map based on a B-Tree.
BTreeSet
An ordered set based on a B-Tree.
BasicError
baic implementation of generic BasicError
BinaryHeap
A priority queue implemented with a binary heap.
DynArray
A contiguous growable array type, written as Vec<T>, short for ‘vector’.
EnumerableIteratorConsumable
Iterator for enumerable.
EnumerableIteratorNonConsumable
Iterator for enumerable.
HashMap
A hash map implemented with quadratic probing and SIMD lookup.
HashSet
A hash set implemented as a HashMap where the value is ().
HomoPair
Type constructor to wrap pair of the same type.
Interval
Alternative implementation of interval.
LinkedList
A doubly-linked list with owned nodes.
Many
Type constructor to wrap a vector.
Map
A hash map implemented with quadratic probing and SIMD lookup.
Pair
Type constructor to wrap two types into a tuple.
Set
A hash set implemented as a HashMap where the value is ().
Single
Type constructor to wrap a another type into a tuple.
Vec
A contiguous growable array type, written as Vec<T>, short for ‘vector’.
VecDeque
A double-ended queue implemented with a growable ring buffer.
_Vec
A contiguous growable array type, written as Vec<T>, short for ‘vector’.

Enums§

Diff
A type returned by the diff_with function.
Either
The enum Either with variants Left and Right is a general purpose sum type with two cases.
EitherOrBoth
Value that either holds a single A or B, or both.
FoldWhile
An enum used for controlling the execution of fold_while.
MinMaxResult
MinMaxResult is an enum returned by minmax.
Position
A value yielded by WithPosition. Indicates the position of this element in the iterator results.

Traits§

AsArray
Reinterpret as array.
AsSlice
Reinterpret as slice.
AsTuple
Reinterpret as tuple.
CloneAsArray
Clone as array.
CloneAsTuple
Clone as tuple.
Enumerable
Has length and indexed access.
ErrorInterface
Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>.
IntervalAdapter
Interval adapter. Interface to interval-like structures.
IsolateOptionsAdapter
Adapter for IsolateOptions.
Itertools
An Iterator blanket implementation that provides extra adaptors and methods.
Make0
Constructor without arguments.
Make1
Constructor with single argument.
Make2
Constructor with two arguments.
Make3
Constructor with three arguments.
ParseOptionsAdapter
Adapter for ParseOptions.
PeekingNext
An iterator that allows peeking at an element before deciding to accept it.
SplitOptionsAdapter
Adapter for Split Options.
VectorizedFrom
Implementation of trait From to vectorize into/from.
VectorizedInto
Implementation of trait Into to vectorize into/from.

Functions§

_clone_boxed
Clone boxed dyn.
all
Test whether the predicate holds for all elements in the iterable.
any
Test whether the predicate holds for any elements in the iterable.
assert_equal
Assert that two iterables produce equal sequences, with the same semantics as equal(a, b).
chain
Takes two iterables and creates a new iterator over both in sequence.
cloned
Create an iterator that clones each element from &T to T
concat
Combine all an iterator’s elements into one element by using Extend.
cons_tuples
Create an iterator that maps for example iterators of ((A, B), C) to (A, B, C).
diff_with
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.
enumerate
Iterate iterable with a running index.
equal
Return true if both iterables produce equal sequences (elements pairwise equal and sequences of the same length), false otherwise.
fold
Perform a fold operation over the iterable.
interleave
Create an iterator that interleaves elements in i and j.
intersperse
Iterate iterable with a particular value inserted between each element.
intersperse_with
Iterate iterable with a particular value created by a function inserted between each element.
iterate
Creates a new iterator that infinitely applies function to value and yields results.
join
Combine all iterator elements into one String, separated by sep.
kmerge
Create an iterator that merges elements of the contained iterators using the ordering function.
kmerge_by
Create an iterator that merges elements of the contained iterators.
max
Return the maximum value of the iterable.
merge
Create an iterator that merges elements in i and j.
merge_join_by
Return an iterator adaptor that merge-joins items from the two base iterators in ascending order.
min
Return the minimum value of the iterable.
multipeek
An iterator adaptor that allows the user to peek at multiple .next() values without advancing the base iterator.
multiunzip
Converts an iterator of tuples into a tuple of containers.
multizip
An iterator that generalizes .zip() and allows running multiple iterators in lockstep.
now
Get current time. Units are milliseconds.
partition
Partition a sequence using predicate pred so that elements that map to true are placed before elements which map to false.
peek_nth
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.
process_results
“Lift” a function of the values of an iterator so that it can process an iterator of Result values instead.
put_back
Create an iterator where you can put back a single item
put_back_n
Create an iterator where you can put back multiple values to the front of the iteration.
rciter
Return an iterator inside a Rc<RefCell<_>> wrapper.
repeat_n
Create an iterator that produces n repetitions of element.
rev
Iterate iterable in reverse.
sorted
Sort all iterator elements into a new iterator in ascending order.
unfold
Creates a new unfold source with the specified closure as the “iterator function” and an initial state to eventually pass to the closure
zipDeprecated
Converts the arguments to iterators and zips them.
zip_eq
Iterate i and j in lock step.

Attribute Macros§

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

Derive Macros§

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