easier
making rust easier!
Set of extensions and methods that make rust a little easier to use for day to day tasks, as well as big projects.
There are also convenience methods, which are sometimes a bit easier to remember, or at the very least require less typing.
Primary goal is to be useful.
Saving time, or a few characters on things we do hundreds of times a day, adds up.
Or making things easier to read makes debugging and understanding code much faster.
Secondary goals:
- Minimize imports
- Minimal build time
If you would like to suggest things that make rust a bit easier to use, you can submit a PR.
Examples
Include: use easier::prelude::*;
lines(path)
Read lines one by one from file. Note, this makes the assumption that you can read from the file, and will panic if it cannot read from file, or file does no exist. This makes just quickly reading lines way simpler, but is less rusty, as we are not passing errors to caller.
easier:
for line in lines
instead of:
//Or can also use ?
for line in new.lines
//Or more fully...
let file = open;
match file
to_vec() for iterators
Use this on iterators instead of .collect::<Vec<_>>()
easier:
let a= .iter.map.to_vec;
instead of:
let a= .iter.map.;
into_vec() for items that impl IntoIterator
Use this on items that impl IntoIterator instead of .into_iter().collect::<Vec<_>>()
easier:
let b = from_iter.into_vec;
instead of:
let a = from_iter.into_iter.;
any()
Instead of !vec.is_empty() use .any() which is easier to read and type.
Can be used on slices, vecs
easier:
if vec.any
instead of:
if !vec.is_empty
convert
This converts between types as long as there is a try_from
This should cover many std types
easier:
use *;
let a: = .convert.unwrap;
let b: = vec!.convert.unwrap;
or convert any errors to the default value with:
let a = .;
or convert any errors to the given value with:
let a: = .convert_or;