-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e08645
commit 2dc0e0a
Showing
4 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::{num::ParseFloatError, str::FromStr}; | ||
|
||
pub struct Angle { | ||
pub radians: f64, | ||
} | ||
|
||
// Never implement From<&str> or From<String> as FromStr is made for this | ||
impl FromStr for Angle { | ||
type Err = ParseFloatError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
let radians = s.parse::<f64>()?; | ||
Ok(Angle { radians }) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_from_str() { | ||
match "1.57".parse::<Angle>() { | ||
Ok(angle) => assert_eq!(angle.radians, 1.57), | ||
Err(_) => panic!("Could not parse angle"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod from_str; | ||
pub mod graphemes; | ||
pub mod mutate_in_closure; | ||
pub mod vec_any; |