2个版本

使用旧的Rust 2015

0.1.1 2018年8月1日
0.1.0 2018年8月1日

#1960数据结构

MIT 许可证

7KB
135

夹紧浮点类型。

提供围绕范围[0,1]夹紧的浮点值的包装。

示例

基本用法

use clampf::Clamp32; // The `Clamp64` type is also available

#[derive(Debug)]
pub struct Color {
    red: Clamp32,   // A value in the range [0,1]
    green: Clamp32, // A value in the range [0,1]
    blue: Clamp32,  // A value in the range [0,1]
}

impl Color {
    pub fn new(red: f32, green: f32, blue: f32) -> Self {
        Color {
            // Check the `red` value
            red: Clamp32::new(red),
            // Check the `green` value
            green: Clamp32::new(green),
            // Check the `blue` value
            blue: Clamp32::new(blue),
        }
    }

    pub fn set_red(&mut self, red: f32) {
        // Check the `red` value
        self.red.set(red);
    }
}

无标准库的用法

对于无标准库的用法,您需要排除 std 功能。这可以通过编辑 Cargo.toml

[dependencies.clampf]
version = "0.1"
default-features = false

[dependencies]
clampf = { version = "0.1", default-features = false }

依赖项

~155KB