Skip to content

Releases: nvzqz/condtype

v1.3.0

20 Aug 20:00
Compare
Choose a tag to compare

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

09 May 15:22
Compare
Choose a tag to compare

Adds if let pattern matching to the condval! macro.

const STR: Option<&str> = // ...

let val = condval!(if let Some(str) = STR {
    str.to_uppercase()
} else {
    42
});

v1.1.0

26 Apr 04:14
Compare
Choose a tag to compare

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 });

v1.0.0

18 Apr 19:50
Compare
Choose a tag to compare

Introduces the CondType type alias.

use condtype::CondType;

let str: CondType<true,  &str, i32> = "hello";
let int: CondType<false, &str, i32> = 42;

This can also be used with !Sized types:

let str: &CondType<true, str, [u8]> = "world";