#selection #inline #parameters #input #targeted #sized #abstraction

platform

Provides an easy way to inline selection of input parameters based on the platform being targeted

3 stable releases

Uses old Rust 2015

1.0.2 Apr 30, 2018
1.0.1 Apr 29, 2018
1.0.0 Apr 27, 2018

#4 in #targeted

Download history 3/week @ 2024-02-15 24/week @ 2024-02-22 19/week @ 2024-02-29 6/week @ 2024-03-07 5/week @ 2024-03-14

55 downloads per month

MIT/Apache

7KB

Crates listing

platform crate

This crate provides an easy way to inline selection of input parameters based on the platform being targeted. Can be used on any Sized type.

This is guaranteed to be a zero cost abstraction, as all calls are inlined.

extern crate platform;

use platform::Platform;

fn main() {
    println!("Hello from {}!", 
        "unknown"
        .ios("ios")
        .android("android")
        .windows("windows")
        .macos("macos")
        .linux("linux")
        .wasm32("wasm32")
        .emscripten("emscripten")
    );
}

lib.rs:

This crate provides an easy way to inline selection of input parameters based on the platform being targeted. Can be used on any Sized type.

This is guaranteed to be a zero cost abstraction, as all calls are inlined.

extern crate platform;

use platform::Platform;

fn main() {
    println!("Hello from {}!",
        "unknown"
        .ios("ios")
        .android("android")
        .windows("windows")
        .macos("macos")
        .linux("linux")
        .wasm32("wasm32")
        .emscripten("emscripten")
    );

    // Alternatively, let's pretend the arguments are non-trivial to evaluate.
    // We can also use this on function pointers so long as all the variants can 
    // coerce to the same function pointer type.
    println!("Hello from {}!",
        ((|| String::from("unknown")) as fn() -> String)
        .ios(|| String::from("ios"))
        .android(|| String::from("android"))
        .windows(|| String::from("windows"))
        .macos(|| String::from("macos"))
        .linux(|| String::from("linux"))
        .wasm32(|| String::from("wasm32"))
        .emscripten(|| String::from("emscripten"))
        ()
    );
}

No runtime deps