Skip to content

Commit

Permalink
Merge #41
Browse files Browse the repository at this point in the history
41: Make `NumOps` work with `no_std` r=cuviper a=jedrzejboczar

This fixes incompatibility with `no_std` Rust.

Co-authored-by: Jędrzej Boczar <yendreij@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
  • Loading branch information
3 people committed Oct 29, 2020
2 parents 2d19853 + b968aa7 commit 61a6e52
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -5,10 +5,10 @@ documentation = "https://docs.rs/num-derive"
homepage = "https://github.com/rust-num/num-derive"
keywords = ["mathematics", "numerics"]
categories = [ "science" ]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
name = "num-derive"
repository = "https://github.com/rust-num/num-derive"
version = "0.3.2"
version = "0.3.3"
readme = "README.md"
exclude = ["/bors.toml", "/ci/*", "/.github/*"]
edition = "2018"
Expand Down
15 changes: 15 additions & 0 deletions README.md
Expand Up @@ -52,3 +52,18 @@ Release notes are available in [RELEASES.md](RELEASES.md).
## Compatibility

The `num-derive` crate is tested for rustc 1.31 and greater.

## License

Licensed under either of

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
6 changes: 6 additions & 0 deletions RELEASES.md
@@ -1,3 +1,9 @@
# Release 0.3.3 (2020-10-29)

- [Make `NumOps` work with `no_std`][41] -- thanks @jedrzejboczar!

[41]: https://github.com/rust-num/num-derive/pull/41

# Release 0.3.2 (2020-08-24)

- [Add `#[inline]` to all derived functions][40] -- thanks @Amanieu!
Expand Down
7 changes: 6 additions & 1 deletion ci/check/src/lib.rs
@@ -1,8 +1,13 @@
#![no_std]

#[derive(num_derive::FromPrimitive)]
use num_derive::*;

#[derive(FromPrimitive, ToPrimitive)]
pub enum ABC {
A,
B,
C,
}

#[derive(PartialEq, FromPrimitive, Num, NumCast, NumOps, One, ToPrimitive, Zero)]
pub struct NewFloat(f32);
20 changes: 10 additions & 10 deletions src/lib.rs
Expand Up @@ -565,39 +565,39 @@ pub fn num_ops(input: TokenStream) -> TokenStream {
let name = &ast.ident;
let inner_ty = newtype_inner(&ast.data).expect(NEWTYPE_ONLY);
let impl_ = quote! {
impl ::std::ops::Add for #name {
impl ::core::ops::Add for #name {
type Output = Self;
#[inline]
fn add(self, other: Self) -> Self {
#name(<#inner_ty as ::std::ops::Add>::add(self.0, other.0))
#name(<#inner_ty as ::core::ops::Add>::add(self.0, other.0))
}
}
impl ::std::ops::Sub for #name {
impl ::core::ops::Sub for #name {
type Output = Self;
#[inline]
fn sub(self, other: Self) -> Self {
#name(<#inner_ty as ::std::ops::Sub>::sub(self.0, other.0))
#name(<#inner_ty as ::core::ops::Sub>::sub(self.0, other.0))
}
}
impl ::std::ops::Mul for #name {
impl ::core::ops::Mul for #name {
type Output = Self;
#[inline]
fn mul(self, other: Self) -> Self {
#name(<#inner_ty as ::std::ops::Mul>::mul(self.0, other.0))
#name(<#inner_ty as ::core::ops::Mul>::mul(self.0, other.0))
}
}
impl ::std::ops::Div for #name {
impl ::core::ops::Div for #name {
type Output = Self;
#[inline]
fn div(self, other: Self) -> Self {
#name(<#inner_ty as ::std::ops::Div>::div(self.0, other.0))
#name(<#inner_ty as ::core::ops::Div>::div(self.0, other.0))
}
}
impl ::std::ops::Rem for #name {
impl ::core::ops::Rem for #name {
type Output = Self;
#[inline]
fn rem(self, other: Self) -> Self {
#name(<#inner_ty as ::std::ops::Rem>::rem(self.0, other.0))
#name(<#inner_ty as ::core::ops::Rem>::rem(self.0, other.0))
}
}
};
Expand Down

0 comments on commit 61a6e52

Please sign in to comment.