diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2023-02-02 21:30:38 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-02-02 21:30:38 +0000 |
commit | 3265c08eca809f3854f0ebeca4f636fc04d0856a (patch) | |
tree | f4824cef7c18434e47696e520e4167a43a0b7c41 | |
parent | 0ce274a1471e416ecadbd68a93811607674442bc (diff) | |
parent | 8d6170288175fffe3b8c8e2e9d02ad56a03a08b6 (diff) | |
download | enumn-3265c08eca809f3854f0ebeca4f636fc04d0856a.tar.gz |
Upgrade enumn to 0.1.6 am: 58941dbeca am: 8d61702881
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/enumn/+/2411750
Change-Id: I51adfcf266c2867b54050d1a52153a479dc2a2b4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .github/FUNDING.yml | 1 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 6 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 3 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | tests/test.rs | 52 |
9 files changed, 69 insertions, 11 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index a98c5bd..081b42b 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "5fbcf35bdfbffed551726f4c681680e8d4b70e7c" + "sha1": "6024ffd9b8fa3bf2da7da4e286980d93706dfa4b" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..7507077 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: dtolnay diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a888ae..bc711bf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: pull_request: schedule: [cron: "40 1 * * *"] +permissions: + contents: read + env: RUSTFLAGS: -Dwarnings @@ -16,6 +19,7 @@ jobs: fail-fast: false matrix: rust: [nightly, beta, stable, 1.31.0] + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -27,6 +31,7 @@ jobs: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@clippy @@ -36,6 +41,7 @@ jobs: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated @@ -41,7 +41,7 @@ rust_proc_macro { name: "libenumn", crate_name: "enumn", cargo_env_compat: true, - cargo_pkg_version: "0.1.5", + cargo_pkg_version: "0.1.6", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.31" name = "enumn" -version = "0.1.5" +version = "0.1.6" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Convert number to enum" documentation = "https://docs.rs/enumn" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index eee91e7..a4b1864 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "enumn" -version = "0.1.5" +version = "0.1.6" authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["rust-patterns", "no-std"] description = "Convert number to enum" @@ -8,7 +8,6 @@ documentation = "https://docs.rs/enumn" edition = "2018" keywords = ["enum", "integer"] license = "MIT OR Apache-2.0" -readme = "README.md" repository = "https://github.com/dtolnay/enumn" rust-version = "1.31" @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/enumn/enumn-0.1.5.crate" + value: "https://static.crates.io/crates/enumn/enumn-0.1.6.crate" } - version: "0.1.5" + version: "0.1.6" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 9 + year: 2023 + month: 2 + day: 1 } } @@ -4,7 +4,7 @@ Convert number to enum [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/enumn-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/enumn) [<img alt="crates.io" src="https://img.shields.io/crates/v/enumn.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/enumn) [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-enumn-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/enumn) -[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/enumn/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/enumn/actions?query=branch%3Amaster) +[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/enumn/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/enumn/actions?query=branch%3Amaster) This crate provides a derive macro to generate a function for converting a primitive integer into the corresponding variant of an enum. diff --git a/tests/test.rs b/tests/test.rs new file mode 100644 index 0000000..3f2daa7 --- /dev/null +++ b/tests/test.rs @@ -0,0 +1,52 @@ +use enumn::N; + +#[derive(Debug, N, PartialEq)] +enum EmptyEnum {} + +#[test] +fn test_empty() { + assert_eq!(EmptyEnum::n(0), None); + assert_eq!(EmptyEnum::n(1), None); + assert_eq!(EmptyEnum::n(-1), None); +} + +#[derive(Debug, N, PartialEq)] +enum SimpleEnum { + Case0, + Case1, +} + +#[test] +fn test_simple() { + assert_eq!(SimpleEnum::n(0), Some(SimpleEnum::Case0)); + assert_eq!(SimpleEnum::n(1), Some(SimpleEnum::Case1)); + assert_eq!(SimpleEnum::n(4), None); + assert_eq!(SimpleEnum::n(-1), None); +} + +#[derive(Debug, N, PartialEq)] +#[repr(u8)] +enum EnumWithRepr { + Case0, +} + +#[test] +fn test_repr() { + assert_eq!(EnumWithRepr::n(0), Some(EnumWithRepr::Case0)); + assert_eq!(EnumWithRepr::n(255), None); +} + +#[derive(Debug, N, PartialEq)] +enum EnumWithDiscriminant { + A = 10, + B, // implicitly 11 + C = -80, +} + +#[test] +fn test_discriminant() { + assert_eq!(EnumWithDiscriminant::n(10), Some(EnumWithDiscriminant::A)); + assert_eq!(EnumWithDiscriminant::n(11), Some(EnumWithDiscriminant::B)); + assert_eq!(EnumWithDiscriminant::n(-80), Some(EnumWithDiscriminant::C)); + assert_eq!(EnumWithDiscriminant::n(12), None); +} |