Crate kai

Source
Expand description

§Description

This library contains my personal Rust prelude and utilities.

§Design goals

  • Remove the hassle of having to add use statements for very common standard library types
  • Reduce the amount of code that actually has to be written
  • Alleviate common Rust pain points

This library is meant to improve your experience writing Rust no matter what you are writing code for. The patterns it tackles are mostly ones that the average Rust programmer encounters on a daily basis.

§Utilities

I have made some very simple utilities to aid in writing Rust code:

§Modules

  • thread Adds custom thread type as well as reexporting std::thread::* for convenience.

§Functions

  • order Functions for fully ordering PartialOrd types
  • close Functions for checking if two floating-point numbers are close enough to be considered equal
  • promote_then Temporarily gain access to an immutable reference as mutable

§Traits

  • BoolMap Maps bools to Options in one line
  • Bind Allows the binding and mutation of a value in a single line
  • KaiIterator Generates my custom iterator adapters

§Structs

  • Adapter Wraps a reference to a string representation of some type
  • Swap Wrapper that allows consuming transformations on borrowed data

§Types

§Macros

  • variant! Maps an enum to an option for use with Iterator::filter_map
  • transparent_mod! Declares transparent external child modules
  • cond_vec! Conditionally construct Vecs

Modules§

close
Functions for checking if two floating-point numbers are close enough to be considered equal
fs
Filesystem manipulation operations.
iter
Composable external iteration.
ops
Overloadable operators.
order
Functions for fully ordering PartialOrd types
thread
My custom smart threads. Also reexports std::thread::* for convenience.

Macros§

cond_vec
Conditionally construct Vecs
transparent_mod
Declares transparent external child modules
variant
Maps an enum to an option for use with Iterator::filter_map

Structs§

Adapter
Wraps a reference to a String representation of some type
Arc
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
Duration
A Duration type to represent a span of time, typically used for system timeouts.
File
An object providing access to an open file on the filesystem.
Formatter
Configuration for formatting.
HashMap
A hash map implemented with quadratic probing and SIMD lookup.
HashSet
A hash set implemented as a HashMap where the value is ().
IntoIter
An iterator that moves out of a vector.
Mutex
A mutual exclusion primitive useful for protecting shared data
Path
A slice of a path (akin to str).
PathBuf
An owned, mutable path (akin to String).
Rc
A single-threaded reference-counting pointer. ‘Rc’ stands for ‘Reference Counted’.
Swap
Wrapper that allows consuming transformations on borrowed data

Enums§

ChainIf
An iterator adaptor created by KaiIterator::chain_if
ChainIfElse
An iterator adaptor created by KaiIterator::chain_if_else
Ordering
An Ordering is the result of a comparison between two values.

Constants§

PI32
Archimedes’ constant (π)
PI64
Archimedes’ constant (π)

Traits§

Bind
Allows the binding and mutation of a value in a single line
BoolMap
Maps bools to Options in one line
BufRead
A BufRead is a type of Reader which has an internal buffer, allowing it to perform extra ways of reading.
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, {}.
Error
Error is a trait representing the basic expectations for error values, i.e., values of type E in Result<T, E>.
FromStr
Parse a value from a string
Index
Used for indexing operations (container[index]) in immutable contexts.
IndexMut
Used for indexing operations (container[index]) in mutable contexts.
KaiIterator
Generates my custom iterator adapters
Read
The Read trait allows for reading bytes from a source.
Write
A trait for objects which are byte-oriented sinks.

Functions§

promote_then
Temporarily gain access to an immutable reference as mutable
stdin
Constructs a new handle to the standard input of the current process.

Type Aliases§

DynResult
An dynamic Result type
FmtResult
An alias for fmt::Result
IoResult
An alias for io::Result

Derive Macros§

Debug
Derive macro generating an impl of the trait Debug.