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§

accio
Alias for dereferencing. This does not use the Deref or DerefMut traits, but prepends * to the start of the given expression.
aparecium
Alias for Box::from_raw. Useful if you have made something invisible with evanesco!. This is unsafe as revealing something invisible might not be what the invisible thing wants, and it might attack you and cause undefined behaviour.
avada_kedavra
Alias for panic!.
capacious_extremis
Alias for Vec::reserve.
colloportus
Alias for Mutex::lock.
erecto
Constructs the given type using either the Default::default or new(<optional args>) functions. Calling it with erecto!(type) results in the former, while erecto!(type: <optional args>) results in the latter.
evanesco
Alias for Box::leak. The item is still there, it’s just invisible. Can be revealed with aparecium!.
expecto_patronum
Appends .expect(message) if given a message, otherwise appends .unwrap().
geminio
Alias for Clone::clone.
immobulus
Alias for Pin::new.
imperio
Alias for mem::transmute. Disregard the rules, force the type system to do what you want!
obliviate
Alias for Drop::drop.
petrificus_totalus
Alias for std::thread::sleep.
reparo
Alias for Result::unwrap_or and Result::unwrap_or_else. Automatically chooses unwrap_or_else if given a closure, and unwrap_or if given an expression that is not a closure.
sonorous
Alias for println!.
unforgivable
Alias for unsafe. What could be more unforgivable than undefined behaviour?