Expand description
§Power Letters for Rust
Concise spellings of common Rust operations:
C
-Clone
O
-ToOwned
S
-ToString
I
- IgnoreResult
X
-expect
forResult
andOption
All operations are provided as both functions and methods. Sometimes one reads better than the other.
§Power Clone
use powerletters::*;
let bagostuff = vec!["a", "b", "c"];
let newbag = bagostuff.C();
// or
let newbag = C(&bagostuff);
§Power ToOwned
use powerletters::*;
use std::path::Path;
let yourpath = Path::new("chill");
let mypath = yourpath.O();
// or
let mypath = O(yourpath);
§Power ToString
use powerletters::*;
let s: String = S("foo");
// or
let s: String = "foo".S();
§Power ignore Result
- kick that Result
to the curb!
use powerletters::*;
use std::io::Write;
let mut buf = Vec::new();
write!(&mut buf, "hello").I();
// or
I(write!(&mut buf, "world"));
Note this is superior to let _ = ...
because the let
version is untyped and can
introduce unintended bugs like ignoring futures.
§Power expect
for Result
and Option
.
use powerletters::*;
let maybe_thing = Some("thing");
let thing = maybe_thing.X(); // like `.expect("some baloney")`
let good_thing: Result<_, io::Error> = Ok("thing");
let thing = good_thing.X();
// or
let maybe_thing = Some("thing");
let thing = X(maybe_thing);
let good_thing: Result<_, io::Error> = Ok("thing");
let thing = X(good_thing);
Traits§
- Power
Clone - Power
Clone
. - Power
Expect - Power
expect
forResult
andOption
. - Power
ToOwned - Power
ToOwned
. - Power
ToString - Power
ToString
. - Result
Ignore - Power ignore
Result
- kick thatResult
to the curb!