Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main
- release/**
schedule:
- cron: '0 3 * * 4'
- cron: "0 3 * * 4"

jobs:
## Run all default oriented feature sets across all platforms.
Expand All @@ -22,49 +22,49 @@ jobs:
#os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v1

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: cargo test --all --all-targets --all-features
run: cargo test --all --all-targets --all-features
- name: cargo test --all --all-targets --all-features
run: cargo test --all --all-targets --all-features

## Execute the clippy checks
cleanliness:
name: cleanliness
runs-on: ubuntu-latest
needs: platform-matrix
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v1

# not using the cargo cache here, since this differs significantly
- name: cargo-all cache
uses: actions/cache@v1
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-all-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-all-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-cargo-all
${{ runner.os }}-cargo
# not using the cargo cache here, since this differs significantly
- name: cargo-all cache
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-all-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-all-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-cargo-all
${{ runner.os }}-cargo

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
# Clippy
- name: cargo clippy
run: cargo clippy --lib --examples --tests --bins --all-features -- -D warnings
# Rustfmt
- name: cargo fmt
run: cargo fmt -- --check
# Audit
- name: cargo audit
run: cargo install cargo-audit && cargo audit --deny warnings
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true

# Clippy
- name: cargo clippy
run: cargo clippy --lib --examples --tests --bins --all-features -- -D warnings
# Rustfmt
- name: cargo fmt
run: cargo fmt -- --check
# Audit
- name: cargo audit
run: cargo install cargo-audit && cargo audit --deny warnings
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ heck = "0.5"
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"

[lints.rust]
missing_copy_implementations = "warn"
missing_docs = "warn"
non_snake_case = "warn"
non_upper_case_globals = "warn"
rust_2018_idioms = "warn"
unreachable_pub = "warn"

[lints.clippy]
default_trait_access = "warn"
dbg_macro = "warn"
print_stdout = "warn"
unimplemented = "warn"
use_self = "warn"
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum OneEnum {
}
```

where the inner item can be retrieved with the `as_*()`/`as_*_mut()` or with the `into_*()` functions:
where the inner item can be retrieved with the `as_*()`/`as_*_mut()`, `into_*()` or with the `*unchecked` functions:

```rust
let one = OneEnum::One(1);
Expand All @@ -28,9 +28,15 @@ let mut one = OneEnum::One(2);
assert_eq!(*one.as_one().unwrap(), 1);
assert_eq!(*one.as_one_mut().unwrap(), 1);
assert_eq!(one.into_one().unwrap(), 1);

unsafe {
assert_eq!(*one.as_one_unchecked(), 1);
assert_eq!(*one.as_one_mut_unchecked(), 1);
assert_eq!(one.into_one_unchecked(), 1);
}
```

where the result is either a reference for inner items or a tuple containing the inner items.
where the result is either a reference for inner items or a tuple containing the inner items. The `*unchecked` functions are unsafe and return either a reference or a tuple containing the inner items.

## Unit case

Expand Down Expand Up @@ -74,6 +80,13 @@ let mut many = ManyVariants::Three(true, 1, 2);
assert_eq!(many.as_three().unwrap(), (&true, &1_u32, &2_i64));
assert_eq!(many.as_three_mut().unwrap(), (&mut true, &mut 1_u32, &mut 2_i64));
assert_eq!(many.into_three().unwrap(), (true, 1_u32, 2_i64));

unsafe {
assert_eq!(many.as_three_unchecked(), (&true, &1_u32, &2_i64));
assert_eq!(many.as_three_mut_unchecked(), (&mut true, &mut 1_u32, &mut 2_i64));
assert_eq!(many.into_three_unchecked(), (true, 1_u32, 2_i64));
}

```

## Multiple, named field case
Expand All @@ -99,4 +112,12 @@ let mut many = ManyVariants::Three{ one: true, two: 1, three: 2 };
assert_eq!(many.as_three().unwrap(), (&true, &1_u32, &2_i64));
assert_eq!(many.as_three_mut().unwrap(), (&mut true, &mut 1_u32, &mut 2_i64));
assert_eq!(many.into_three().unwrap(), (true, 1_u32, 2_i64));

unsafe {
assert_eq!(many.as_three_unchecked(), (&true, &1_u32, &2_i64));
assert_eq!(many.as_three_mut_unchecked(), (&mut true, &mut 1_u32, &mut 2_i64));
assert_eq!(many.into_three_unchecked(), (true, 1_u32, 2_i64));
}


```
Loading
Loading