Releases: nvzqz/condtype
Releases · nvzqz/condtype
v1.3.0
Adds num
module containing conditional aliases to numeric types.
use std::fs::File;
use condtype::num::Usize64;
fn handle_throughput(bytes: Usize64) {
// ...
}
// usize
let s: &str = // ...
handle_throughput(s.len() as Usize64);
// u64
let f: File = // ...
handle_throughput(f.metadata()?.len() as Usize64);
v1.2.0
v1.1.0
Introduces the condval!
macro to instantiate a conditionally-typed value.
Attempting to return different types from if
/else
is not normally possible since both branches must produce the same type:
let val = if true { "hello" } else { 42 };
This macro enables returning different types by making the type be conditional on a const
bool
:
use condtype::condval;
let val: &str = condval!(if true { "hello" } else { 42 });
let val: i32 = condval!(if false { "hello" } else { 42 });