Skip to content

Commit

Permalink
Use TryFrom since it is stable
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 committed Apr 19, 2019
1 parent 76d20ff commit af12d60
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 202 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ syn = "0.12.13"

[features]
const-fn = []
try-from = []
15 changes: 5 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ fn main() {
cast_asserts.push(quote! {
assert_eq!(f64(#qx_name(#qy_name(0.5_f64).unwrap()).unwrap()), 0.5);
});
if cfg!(feature = "try-from") {
try_from_asserts.push(quote! {
assert_eq!(f64::from(#qx_name::try_from(#qy_name::try_from(0.5_f64).unwrap()).unwrap()), 0.5);
});
}
try_from_asserts.push(quote! {
assert_eq!(f64::from(#qx_name::try_from(#qy_name::try_from(0.5_f64).unwrap()).unwrap()), 0.5);
});
} else {
cast_asserts.push(quote! {
assert_eq!(f64(#qx_name(#qy_name(0.5_f64).unwrap())), 0.5);
Expand All @@ -163,7 +161,6 @@ fn main() {
}

#[test]
#[cfg(feature = "try-from")]
fn try_from() {
#(#try_from_asserts)*
}
Expand Down Expand Up @@ -201,7 +198,7 @@ fn main() {
cast_asserts.push(quote! {
assert_eq!(#p_name(#q_name(#f).unwrap()).unwrap(), #i as #p_name);
});
if cfg!(feature = "try-from") && !p.is_pointer_sized() {
if !p.is_pointer_sized() {
try_from_asserts.push(quote! {
assert_eq!(#p_name::try_from(#q_name::try_from(#f).unwrap()).unwrap(), #i as #p_name);
});
Expand Down Expand Up @@ -232,7 +229,6 @@ fn main() {
}

#[test]
#[cfg(feature = "try-from")]
fn try_from() {
#(#try_from_asserts)*
}
Expand Down Expand Up @@ -275,7 +271,7 @@ fn main() {
cast_asserts.push(quote! {
assert_eq!(f64(#q_name(#i as #p_name).unwrap()), #i as f64);
});
if cfg!(feature = "try-from") && !p.is_pointer_sized() {
if !p.is_pointer_sized() {
try_from_asserts.push(quote! {
assert_eq!(f64::from(#q_name::try_from(#i as #p_name).unwrap()), #i as f64);
});
Expand All @@ -297,7 +293,6 @@ fn main() {
}

#[test]
#[cfg(feature = "try-from")]
fn try_from() {
#(#try_from_asserts)*
}
Expand Down
Loading

0 comments on commit af12d60

Please sign in to comment.