Crate code_spells
source ·Expand description
Do you think Rust macros are a bit like magic? I do too!
With this crate you can live your wizard dreams right in your source code. It aliases some common (and some less common) code snippets to macros named after thematically appropriate spells from Harry Potter.
This enables you to cast geminio!(item)
instead of forcing you to call item.clone()
.
let v1 = vec![erecto!(i32); 5];
let mut v2 = geminio!(&v1);
obliviate!(v1);
accio!(expecto_patronum!(v2.get_mut(0), "Dementors B-gone!")) = 5;
Also aliases unsafe
to the macro unforgivable!
,
because what could be more unforgivable than undefined behaviour?
Macros
- Alias for
Box::from_raw
. Useful if you have made something invisible withevanesco!
. This isunsafe
as revealing something invisible might not be what the invisible thing wants, and it might attack you and cause undefined behaviour. - Alias for
panic!
. - Alias for
Vec::reserve
. - Alias for
Mutex::lock
. - Constructs the given type using either the
Default::default
ornew(<optional args>)
functions. Calling it witherecto!(type)
results in the former, whileerecto!(type: <optional args>)
results in the latter. - Alias for
Box::leak
. The item is still there, it’s just invisible. Can be revealed withaparecium!
. - Appends
.expect(message)
if given a message, otherwise appends.unwrap()
. - Alias for
Clone::clone
. - Alias for
Pin::new
. - Alias for
mem::transmute
. Disregard the rules, force the type system to do what you want! - Alias for
Drop::drop
. - Alias for
std::thread::sleep
. - Alias for
Result::unwrap_or
andResult::unwrap_or_else
. Automatically choosesunwrap_or_else
if given a closure, andunwrap_or
if given an expression that is not a closure. - Alias for
println!
. - Alias for unsafe. What could be more unforgivable than undefined behaviour?