Skip to content

Commit

Permalink
support rocket, update MSRV
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Dec 17, 2023
1 parent ced7f8f commit 5e4bd34
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 11 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ jobs:
-
- --features u128
- --features serde
- --features rocket
- --features bit
- --features bit --features serde
- --features bit --features rocket
- --features u128 --features serde
- --features u128 --features bit
- --features u128 --features bit --features serde
- --no-default-features
- --no-default-features --features byte
- --no-default-features --features byte --features serde
- --no-default-features --features byte --features rocket
- --no-default-features --features bit
- --no-default-features --features bit --features serde
- --no-default-features --features bit --features rocket
- --no-default-features --features byte --features bit
- --no-default-features --features u128
- --no-default-features --features u128 --features byte
Expand All @@ -60,21 +64,25 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- "1.60"
- 1.69
features:
-
- --features u128
- --features serde
- --features rocket
- --features bit
- --features bit --features serde
- --features bit --features rocket
- --features u128 --features serde
- --features u128 --features bit
- --features u128 --features bit --features serde
- --no-default-features
- --no-default-features --features byte
- --no-default-features --features byte --features serde
- --no-default-features --features byte --features rocket
- --no-default-features --features bit
- --no-default-features --features bit --features serde
- --no-default-features --features bit --features rocket
- --no-default-features --features byte --features bit
- --no-default-features --features u128
- --no-default-features --features u128 --features byte
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ jobs:
-
- --features u128
- --features serde
- --features rocket
- --features bit
- --features bit --features serde
- --features bit --features rocket
- --features u128 --features serde
- --features u128 --features bit
- --features u128 --features bit --features serde
- --no-default-features
- --no-default-features --features byte
- --no-default-features --features byte --features serde
- --no-default-features --features byte --features rocket
- --no-default-features --features bit
- --no-default-features --features bit --features serde
- --no-default-features --features bit --features rocket
- --no-default-features --features byte --features bit
- --no-default-features --features u128
- --no-default-features --features u128 --features byte
Expand All @@ -76,21 +80,25 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- "1.60"
- 1.69
features:
-
- --features u128
- --features serde
- --features rocket
- --features bit
- --features bit --features serde
- --features bit --features rocket
- --features u128 --features serde
- --features u128 --features bit
- --features u128 --features bit --features serde
- --no-default-features
- --no-default-features --features byte
- --no-default-features --features byte --features serde
- --no-default-features --features byte --features rocket
- --no-default-features --features bit
- --no-default-features --features bit --features serde
- --no-default-features --features bit --features rocket
- --no-default-features --features byte --features bit
- --no-default-features --features u128
- --no-default-features --features u128 --features byte
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "byte-unit"
version = "5.0.4"
version = "5.1.0"
authors = ["Magic Len <[email protected]>"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.69"
repository = "https://github.com/magiclen/byte-unit"
homepage = "https://magiclen.org/byte-unit"
keywords = ["byte", "unit", "kb", "mb", "gb"]
Expand All @@ -16,6 +16,7 @@ include = ["src/**/*", "Cargo.toml", "README.md", "LICENSE"]
utf8-width = "0.1"

serde = { version = "1", default-features = false, features = ["alloc"], optional = true }
rocket = { version = "0.5", optional = true }
rust_decimal = { version = "1", default-features = false, optional = true }

[dev-dependencies]
Expand All @@ -25,9 +26,10 @@ serde_json = "1"
default = ["std", "byte"]

serde = ["dep:serde"]
rocket = ["dep:rocket", "std"]
rust_decimal = ["dep:rust_decimal"]

std = ["serde?/std"]
std = ["serde?/std", "rust_decimal?/std"]
u128 = []
byte = ["rust_decimal"]
bit = ["rust_decimal"]
Expand Down
4 changes: 3 additions & 1 deletion src/bit/adjusted/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod built_in_traits;
#[cfg(feature = "rocket")]
mod rocket_traits;
#[cfg(feature = "serde")]
mod serde;
mod serde_traits;

use core::{
cmp::Ordering,
Expand Down
25 changes: 25 additions & 0 deletions src/bit/adjusted/rocket_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;

use rocket::{
form::{self, FromFormField, ValueField},
request::FromParam,
};

use super::AdjustedBit;
use crate::ParseError;

impl<'r> FromParam<'r> for AdjustedBit {
type Error = ParseError;

#[inline]
fn from_param(v: &'r str) -> Result<Self, Self::Error> {
Self::from_str(v)
}
}

impl<'r> FromFormField<'r> for AdjustedBit {
#[inline]
fn from_value(v: ValueField<'r>) -> form::Result<'r, Self> {
Ok(Self::from_str(v.value).map_err(form::Error::custom)?)
}
}
File renamed without changes.
4 changes: 3 additions & 1 deletion src/bit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ mod built_in_traits;
mod constants;
mod decimal;
mod parse;
#[cfg(feature = "rocket")]
mod rocket_traits;
#[cfg(feature = "serde")]
mod serde;
mod serde_traits;

use core::fmt::{self, Alignment, Display, Formatter, Write};

Expand Down
25 changes: 25 additions & 0 deletions src/bit/rocket_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;

use rocket::{
form::{self, FromFormField, ValueField},
request::FromParam,
};

use super::Bit;
use crate::ParseError;

impl<'r> FromParam<'r> for Bit {
type Error = ParseError;

#[inline]
fn from_param(v: &'r str) -> Result<Self, Self::Error> {
Self::from_str(v)
}
}

impl<'r> FromFormField<'r> for Bit {
#[inline]
fn from_value(v: ValueField<'r>) -> form::Result<'r, Self> {
Ok(Self::from_str(v.value).map_err(form::Error::custom)?)
}
}
File renamed without changes.
4 changes: 3 additions & 1 deletion src/byte/adjusted/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod built_in_traits;
#[cfg(feature = "rocket")]
mod rocket_traits;
#[cfg(feature = "serde")]
mod serde;
mod serde_traits;

use core::{
cmp::Ordering,
Expand Down
25 changes: 25 additions & 0 deletions src/byte/adjusted/rocket_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;

use rocket::{
form::{self, FromFormField, ValueField},
request::FromParam,
};

use super::AdjustedByte;
use crate::ParseError;

impl<'r> FromParam<'r> for AdjustedByte {
type Error = ParseError;

#[inline]
fn from_param(v: &'r str) -> Result<Self, Self::Error> {
Self::from_str(v)
}
}

impl<'r> FromFormField<'r> for AdjustedByte {
#[inline]
fn from_value(v: ValueField<'r>) -> form::Result<'r, Self> {
Ok(Self::from_str(v.value).map_err(form::Error::custom)?)
}
}
File renamed without changes.
4 changes: 3 additions & 1 deletion src/byte/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ mod built_in_traits;
mod constants;
mod decimal;
mod parse;
#[cfg(feature = "rocket")]
mod rocket_traits;
#[cfg(feature = "serde")]
mod serde;
mod serde_traits;

use core::fmt::{self, Alignment, Display, Formatter, Write};

Expand Down
25 changes: 25 additions & 0 deletions src/byte/rocket_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;

use rocket::{
form::{self, FromFormField, ValueField},
request::FromParam,
};

use super::Byte;
use crate::ParseError;

impl<'r> FromParam<'r> for Byte {
type Error = ParseError;

#[inline]
fn from_param(v: &'r str) -> Result<Self, Self::Error> {
Self::from_str(v)
}
}

impl<'r> FromFormField<'r> for Byte {
#[inline]
fn from_value(v: ValueField<'r>) -> form::Result<'r, Self> {
Ok(Self::from_str(v.value).map_err(form::Error::custom)?)
}
}
File renamed without changes.
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ features = ["serde"]
#[cfg(feature = "serde")]
#[macro_use]
extern crate alloc;
extern crate core;
#[cfg(feature = "rust_decimal")]
pub extern crate rust_decimal;

Expand Down
4 changes: 3 additions & 1 deletion src/unit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod built_in_trait;
pub(crate) mod parse;
#[cfg(feature = "rocket")]
mod rocket_traits;
#[cfg(feature = "serde")]
mod serde;
mod serde_traits;
#[cfg(any(feature = "byte", feature = "bit"))]
mod unit_type;

Expand Down
25 changes: 25 additions & 0 deletions src/unit/rocket_traits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::str::FromStr;

use rocket::{
form::{self, FromFormField, ValueField},
request::FromParam,
};

use super::Unit;
use crate::UnitParseError;

impl<'r> FromParam<'r> for Unit {
type Error = UnitParseError;

#[inline]
fn from_param(v: &'r str) -> Result<Self, Self::Error> {
Self::from_str(v)
}
}

impl<'r> FromFormField<'r> for Unit {
#[inline]
fn from_value(v: ValueField<'r>) -> form::Result<'r, Self> {
Ok(Self::from_str(v.value).map_err(form::Error::custom)?)
}
}
File renamed without changes.

0 comments on commit 5e4bd34

Please sign in to comment.