Thread with 4 posts

jump to expanded post

rust question. a common pattern in code i’ve written is:

assert!(foo % bar == 0);
let count = foo / bar;

is there a standard way to do that as a single operation?

one of the things i really like about rust is how it helps you avoid errors by combining an assertion of some assumption (e.g. “foo is not None”) with obtaining a value based on that assumption (e.g. getting the value inside the Some()). so in this case, it’d be really nice if i could do something like foo.div_exact(bar).unwrap(). personally i’d put it in the stdlib…

Open thread at this post