| Crates.io | powerletters |
| lib.rs | powerletters |
| version | 0.3.1 |
| created_at | 2025-10-07 19:41:52.759282+00 |
| updated_at | 2025-10-07 21:23:26.260037+00 |
| description | Concise spellings of common Rust operations |
| homepage | |
| repository | https://github.com/brson/powerletters |
| max_upload_size | |
| id | 1872696 |
| size | 15,460 |
Concise spellings of common Rust operations:
C - CloneO - ToOwnedS - ToStringI - Ignore ResultX - expect for Result and OptionAll operations are provided as both functions and methods. Sometimes one reads better than the other.
In action:
let mut parents: Vec<_> = path.ancestors().skip(1).map(|path| {
if path == Path::new("") {
let parent_path = pathgen.from_path(path).X();
let parent_label = S("<root>");
(parent_path, parent_label)
} else {
let parent_path = pathgen.from_path(path).X();
let parent_label = path.iter().last().X().to_string_lossy().S();
(parent_path, parent_label)
}
}).collect();
Cloneuse powerletters::*;
let bagostuff = vec!["a", "b", "c"];
let newbag = bagostuff.C();
// or
let newbag = C(&bagostuff);
ToOwneduse powerletters::*;
let yourpath = Path::new("chill");
let mypath = yourpath.O();
// or
let mypath = O(yourpath);
ToStringuse powerletters::*;
let s: String = S("foo");
// or
let s: String = "foo".S();
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.
expect for Result and Option.use powerletters::*;
let maybe_thing = Some("thing");
let thing = maybe_thing.X(); // like `.expect("some baloney")`
let good_thing = Ok("thing");
let thing = good_thing.X();
// or
let thing = X(maybe_thing);
let thing = X(good_thing);
Panics with helpful messages:
let none: Option<i32> = None;
let value = none.X();
// thread 'main' panicked at src/main.rs:3:19:
// impossible `None` option
let err: Result<i32, _> = Err("something went wrong");
let value = err.X();
// thread 'main' panicked at src/main.rs:3:18:
// impossible `Err` result: something went wrong