#pointer #reference #unwrap #extension #readability


“Wait why did I put a * in front of that variable yesterday?” - If var is a Box, use var.unbox_ref() instead of &*var for better readability

1 unstable release

0.1.0 May 4, 2021

#3 in #readability


59 lines


This crate provides .unbox_ref() and .unbox_mut() methods on Box types. They are equivalent to .deref() and .deref_mut(), but make it easier to see that the variable that is being operated on is of type Box.


The idea for this crate came to me this morning when I woke up to this code

let expr: &syn::ExprLit = match &*assignment.expr { ... };

and was very unsure as to why there was a deref operator * in front of my variable. Now I just import

unbox-box = "0.1"

and I can replace this code with

use unbox_box::BoxExt as _;
let expr: &syn::ExprLit = match assignment.expr.unbox_ref() { ... };

When I wake up to this code tomorrow, I'm pretty sure I'll recognize that assignment.expr is a Box. Wish me luck!


Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps