make {from,to}_{be,le,ne}_bytes const functions

This commit is contained in:
Trevor Spiteri 2020-06-04 18:18:01 +02:00
parent cd8ee00eac
commit ef36b4f767
6 changed files with 41 additions and 17 deletions

View File

@ -22,7 +22,7 @@ install:
- curl -sSf -o rustup-init.exe https://win.rustup.rs
- rustup-init.exe -y --default-host %TARGET% --default-toolchain none --no-modify-path
- rustup --version
- rustup toolchain install --profile minimal beta-%TARGET% 1.43.0-%TARGET%
- rustup toolchain install --profile minimal beta-%TARGET% 1.44.0-%TARGET%
- rustup component add --toolchain beta-%TARGET% rustfmt clippy
build: false
@ -51,7 +51,7 @@ test_script:
- cargo +beta-%TARGET% check --all-targets --features fail-on-warnings
- cargo +beta-%TARGET% test --release --features "fail-on-warnings az f16 serde"
- cargo +beta-%TARGET% fmt -- --check
- cargo +1.43.0-%TARGET% test --lib --features "fail-on-warnings az f16 serde"
- cargo +1.44.0-%TARGET% test --lib --features "fail-on-warnings az f16 serde"
after_test:
- bash -c "if [ -d $USERPROFILE/.cargo/registry/cache ]; then cd $USERPROFILE/.cargo/registry; for c in cache/*/*.crate; do s=src/${c#cache/}; if [ ! -e ${s/.crate/} ]; then rm -v $c; fi; done; find cache -name \*.crate | sort; fi"

View File

@ -9,7 +9,7 @@ before_script:
- getconf LONG_BIT
- rustup self update
- rustup --version
- rustup toolchain install --profile minimal beta-$TARGET 1.43.0-$TARGET
- rustup toolchain install --profile minimal beta-$TARGET 1.44.0-$TARGET
- rustup component add --toolchain beta-$TARGET rustfmt clippy
- if [ -d cargo/registry/cache ]; then rm -rf $CARGO_HOME/registry/cache; mkdir -p $CARGO_HOME/registry; cp -R cargo/registry/cache $CARGO_HOME/registry/; echo Copied registry/cache; fi
- if [ -d $CARGO_HOME/registry/src ]; then rm -r $CARGO_HOME/registry/src; fi
@ -50,8 +50,8 @@ x86_64-gnulinux:
- cargo +beta-$TARGET test --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.43.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.43.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.44.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.44.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
i686-gnulinux:
image: i386/rust:1
@ -82,8 +82,8 @@ i686-gnulinux:
- cargo +beta-$TARGET test --features "fail-on-warnings f16 serde"
- cargo +beta-$TARGET test --release --features "fail-on-warnings az f16 serde std"
- cargo +beta-$TARGET fmt -- --check
- cargo +1.43.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.43.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.44.0-$TARGET test --lib --features "fail-on-warnings az f16 serde std"
- cargo +1.44.0-$TARGET test --release --lib --features "fail-on-warnings az f16 serde std"
x86_64-gnulinux-tarpaulin:
image: amd64/rust:1

View File

@ -80,9 +80,21 @@ The conversions supported cover the following cases.
### Version 1.0.0 news (unreleased)
* The crate now requires rustc version 1.43.0 or later.
* The crate now requires rustc version 1.44.0 or later.
* The following methods are now `const` functions:
* [`from_be_bytes`][f-fbb-1-0], [`from_le_bytes`][f-flb-1-0],
[`from_ne_bytes`][f-fnb-1-0]
* [`to_be_bytes`][f-tbb-1-0], [`to_le_bytes`][f-tlb-1-0],
[`to_ne_bytes`][f-tnb-1-0]
* All deprecated items were removed.
[f-fbb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be_bytes
[f-flb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_le_bytes
[f-fnb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_ne_bytes
[f-tbb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_be_bytes
[f-tlb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_le_bytes
[f-tnb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_ne_bytes
### Version 0.5.7 news (2020-05-11)
* The [`LosslessTryFrom`][ltf-0-5-7] and
@ -204,7 +216,7 @@ it in your crate, add it as a dependency inside [*Cargo.toml*]:
fixed = "0.5.7"
```
The *fixed* crate requires rustc version 1.43.0 or later.
The *fixed* crate requires rustc version 1.44.0 or later.
## Optional features

View File

@ -8,9 +8,21 @@ as-is, without any warranty. -->
Version 1.0.0 (unreleased)
==========================
* The crate now requires rustc version 1.43.0 or later.
* The crate now requires rustc version 1.44.0 or later.
* The following methods are now `const` functions:
* [`from_be_bytes`][f-fbb-1-0], [`from_le_bytes`][f-flb-1-0],
[`from_ne_bytes`][f-fnb-1-0]
* [`to_be_bytes`][f-tbb-1-0], [`to_le_bytes`][f-tlb-1-0],
[`to_ne_bytes`][f-tnb-1-0]
* All deprecated items were removed.
[f-fbb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be_bytes
[f-flb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_le_bytes
[f-fnb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_ne_bytes
[f-tbb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_be_bytes
[f-tlb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_le_bytes
[f-tnb-1-0]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.to_ne_bytes
Version 0.5.7 (2020-05-11)
==========================

View File

@ -150,7 +150,7 @@ it in your crate, add it as a dependency inside [*Cargo.toml*]:
fixed = "0.5.7"
```
The *fixed* crate requires rustc version 1.43.0 or later.
The *fixed* crate requires rustc version 1.44.0 or later.
## Optional features

View File

@ -107,7 +107,7 @@ assert_eq!(
```
";
#[inline]
pub fn from_be_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
pub const fn from_be_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
$Fixed::from_bits(<$Inner>::from_be_bytes(bytes))
}
}
@ -128,7 +128,7 @@ assert_eq!(
```
";
#[inline]
pub fn from_le_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
pub const fn from_le_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
$Fixed::from_bits(<$Inner>::from_le_bytes(bytes))
}
}
@ -153,7 +153,7 @@ assert_eq!(
```
";
#[inline]
pub fn from_ne_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
pub const fn from_ne_bytes(bytes: [u8; $nbytes]) -> $Fixed<Frac> {
$Fixed::from_bits(<$Inner>::from_ne_bytes(bytes))
}
}
@ -175,7 +175,7 @@ assert_eq!(
```
";
#[inline]
pub fn to_be_bytes(self) -> [u8; $nbytes] {
pub const fn to_be_bytes(self) -> [u8; $nbytes] {
self.to_bits().to_be_bytes()
}
}
@ -197,7 +197,7 @@ assert_eq!(
```
";
#[inline]
pub fn to_le_bytes(self) -> [u8; $nbytes] {
pub const fn to_le_bytes(self) -> [u8; $nbytes] {
self.to_bits().to_le_bytes()
}
}
@ -223,7 +223,7 @@ assert_eq!(
```
";
#[inline]
pub fn to_ne_bytes(self) -> [u8; $nbytes] {
pub const fn to_ne_bytes(self) -> [u8; $nbytes] {
self.to_bits().to_ne_bytes()
}
}