Skip to content

Commit 48e6ee4

Browse files
committed
Added FromPrimitive for u32 and i32
Closes #7
1 parent 2103806 commit 48e6ee4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "piston-float"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
authors = ["bvssvni <bvssvni@gmail.com>"]
66
keywords = ["float", "piston"]
77
description = "Traits for generic floats in game development"

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ pub trait FromPrimitive {
270270
fn from_f32(t: f32) -> Self;
271271
/// from a isze
272272
fn from_isize(t: isize) -> Self;
273+
/// from a u32
274+
fn from_u32(t: u32) -> Self;
275+
/// from a i32
276+
fn from_i32(t: i32) -> Self;
273277
// Add more as needed..
274278
}
275279

@@ -280,6 +284,10 @@ impl FromPrimitive for f64 {
280284
fn from_f32(t: f32) -> Self { t as f64 }
281285
#[inline(always)]
282286
fn from_isize(t: isize) -> Self { t as f64 }
287+
#[inline(always)]
288+
fn from_u32(t: u32) -> Self { t as f64 }
289+
#[inline(always)]
290+
fn from_i32(t: i32) -> Self { t as f64 }
283291
}
284292

285293
impl FromPrimitive for f32 {
@@ -289,6 +297,10 @@ impl FromPrimitive for f32 {
289297
fn from_f32(t: f32) -> Self { t }
290298
#[inline(always)]
291299
fn from_isize(t: isize) -> Self { t as f32 }
300+
#[inline(always)]
301+
fn from_u32(t: u32) -> Self { t as f32 }
302+
#[inline(always)]
303+
fn from_i32(t: i32) -> Self { t as f32 }
292304
}
293305

294306
#[cfg(test)]

0 commit comments

Comments
 (0)