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
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 macroimplements
. - 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§
- BTree
Map - An ordered map based on a B-Tree.
- BTree
Set - An ordered set based on a B-Tree.
- Basic
Error - baic implementation of generic BasicError
- Binary
Heap - A priority queue implemented with a binary heap.
- DynArray
- A contiguous growable array type, written as
Vec<T>
, short for ‘vector’. - Enumerable
Iterator Consumable - Iterator for enumerable.
- Enumerable
Iterator NonConsumable - 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()
. - Homo
Pair - Type constructor to wrap pair of the same type.
- Interval
- Alternative implementation of interval.
- Linked
List - 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 variantsLeft
andRight
is a general purpose sum type with two cases. - Either
OrBoth - Value that either holds a single A or B, or both.
- Fold
While - An enum used for controlling the execution of
fold_while
. - MinMax
Result MinMaxResult
is an enum returned byminmax
.- 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.
- Clone
AsArray - Clone as array.
- Clone
AsTuple - Clone as tuple.
- Enumerable
- Has length and indexed access.
- Error
Interface Error
is a trait representing the basic expectations for error values, i.e., values of typeE
inResult<T, E>
.- Interval
Adapter - Interval adapter. Interface to interval-like structures.
- Isolate
Options Adapter - 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.
- Parse
Options Adapter - Adapter for ParseOptions.
- Peeking
Next - An iterator that allows peeking at an element before deciding to accept it.
- Split
Options Adapter - Adapter for Split Options.
- Vectorized
From - Implementation of trait From to vectorize into/from.
- Vectorized
Into - 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
andj
with the given function in lock-step and returns aDiff
which describes howj
differs fromi
. - 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
andj
. - 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
andj
. - 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 totrue
are placed before elements which map tofalse
. - peek_
nth - A drop-in replacement for
std::iter::Peekable
which adds apeek_nth
method allowing the user topeek
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 ofelement
. - 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
- zip
Deprecated - Converts the arguments to iterators and zips them.
- zip_eq
- Iterate
i
andj
in lock step.
Attribute Macros§
- clone_
dyn - Derive macro to generate former for a structure. Former is variation of Builder Pattern.