Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(enum_pipeline): Add initial implementation
- Loading branch information
0 parents
commit 6052396
Showing
14 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
1
.actrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:rust-18.04 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Basic dependabot.yml file with rust (cargo) configuration. | ||
|
||
version: 2 | ||
updates: | ||
# Enable version updates for cargo (crates.io) | ||
- package-ecosystem: "cargo" | ||
# Look for `Cargo.toml` and `lock` files in the `root` directory | ||
directory: "/" | ||
# Check the registry for updates every day (weekdays) | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This is a basic workflow to ensure code builds and passes tests. | ||
|
||
name: CI | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on pull_request and push but only when the target is the main branch | ||
pull_request: | ||
branches: [main] | ||
push: | ||
branches: [main] | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checkout our code | ||
- uses: actions/checkout@v2 | ||
# Install Just, so we can use our Justfile in the action | ||
- run: cargo install just | ||
# Install necessary tools | ||
- run: just install-tools | ||
# Check our code | ||
- run: just check | ||
# Run tests | ||
- run: just test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# This is a basic workflow to generate release artifacts for rust projects | ||
# It requires a [Repository secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets#creating-encrypted-secrets-for-a-repository) | ||
# For `cargo publish` that can be obtained [here](https://crates.io/me) | ||
# CARGO_REGISTRY_TOKEN: <your_token> | ||
|
||
name: Release | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push but only for the main branch | ||
push: | ||
branches: [main] | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "release" | ||
release: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Use `release-please` to track changes and generate release PRs | ||
- uses: GoogleCloudPlatform/release-please-action@v2 | ||
id: release | ||
with: | ||
release-type: rust | ||
# The name of your crate | ||
package-name: "{{ crate_name }}" | ||
# The logic below handles the crates.io publication: | ||
- uses: actions/checkout@v2 | ||
# these if statements ensure that a publication only occurs when | ||
# a new release is created: | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Install Just, so we can use our Justfile in the action | ||
- run: cargo install just | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Install necessary tools | ||
- run: just install-tools | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Check our code | ||
- run: just check | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Run tests | ||
- run: just test | ||
if: ${{ steps.release.outputs.release_created }} | ||
# Publish the crate (note: release-please will have updated the Cargo.toml for us, so it should already have the correct version) | ||
- run: just publish | ||
if: ${{ steps.release.outputs.release_created }} | ||
env: | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
12
.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
|
||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk |
14
Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "enum_pipeline" | ||
description = "Provides a way to use enums to describe and execute ordered data pipelines." | ||
license = "mit" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
enum_pipeline_derive = {path = "derive", version = "0.1.0"} | ||
|
||
[workspace] | ||
members = ["derive"] |
28
Justfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# You'll need just to get started: `cargo install just` | ||
# just manual: https://github.com/casey/just/#readme | ||
|
||
_default: | ||
@just --list | ||
|
||
|
||
# Installs tools needed for other `just` recipes | ||
install-tools: | ||
cargo install cargo-hack cargo-bump cargo-workspaces | ||
|
||
|
||
# Checks (using `clippy`) all crates across all features | ||
check: | ||
cargo hack --feature-powerset --exclude-no-default-features clippy --locked -- -D warnings | ||
|
||
# Tests all crates across all features | ||
test: | ||
cargo hack --feature-powerset --exclude-no-default-features test --locked | ||
|
||
# Sets the version of the crate to `version` | ||
set-version version: | ||
cargo bump 0.1.0 | ||
|
||
|
||
# Attempts to publish the crate using `cargo workspaces` | ||
publish: | ||
cargo workspaces publish --from-git --no-git-commit --no-git-push --no-git-tag -y |
21
LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 bengreenier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
85
README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# enum-pipeline | ||
|
||
Provides a way to use enums to describe and execute ordered data pipelines. 🦀🐾 | ||
|
||
[](https://github.com/bengreenier/enum-pipeline/actions/workflows/ci.yml) | ||
[](https://crates.io/crates/enum-pipeline) | ||
[](https://docs.rs/enum-pipeline) | ||
[](https://deps.rs/repo/github/bengreenier/enum-pipeline) | ||
|
||
I needed a succinct way to describe 2d pixel map operations for a game I'm working on. I wanted callers to be able to easily determine all possible operations (hence `enum`), with per-operation data (hence variants), and their operation-specific logic. This is what I came up with! | ||
|
||
## Quickstart | ||
|
||
Some quick examples to get you started. For more information see [docs.rs/enum_pipeline](https://docs.rs/enum_pipeline) and [docs.rs/enum_pipeline_derive](https://docs.rs/enum_pipeline_derive). | ||
|
||
### Derive | ||
|
||
``` | ||
#[derive(Default)] | ||
struct MacroMutRefData { | ||
a_count: i32, | ||
b_count: i32, | ||
} | ||
#[derive(ExecuteWithMut)] | ||
#[execute_with(MacroMutRefData)] | ||
enum MacroMutRefPipeline { | ||
#[handler(handle_a)] | ||
A(i32), | ||
#[handler(handle_b)] | ||
B, | ||
} | ||
impl MacroMutRefPipeline { | ||
fn handle_a(i: i32, arg: &mut MacroMutRefData) { | ||
arg.a_count += 1; | ||
} | ||
fn handle_b(arg: &mut MacroMutRefData) { | ||
arg.b_count += 1; | ||
} | ||
} | ||
``` | ||
|
||
Then create and execute some pipelines: | ||
|
||
``` | ||
let mut arg = MacroMutRefData::default(); | ||
vec![MacroMutRefPipeline::A(23), MacroMutRefPipeline::B].execute_with_mut(&mut arg); | ||
``` | ||
|
||
### Manual | ||
|
||
``` | ||
#[derive(Default)] | ||
struct MutRefData { | ||
a_count: i32, | ||
b_count: i32, | ||
} | ||
enum MutRefPipeline { | ||
A(i32), | ||
B, | ||
} | ||
impl ExecuteWithMut<MutRefData> for MutRefPipeline { | ||
fn execute_with_mut(self, arg: &mut MutRefData) { | ||
match self { | ||
MutRefPipeline::A(i) => arg.a_count += 1, | ||
MutRefPipeline::B => arg.b_count += 1, | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Then create and execute some pipelines: | ||
|
||
``` | ||
let mut arg = MutRefData::default(); | ||
vec![MutRefPipeline::A(23), MutRefPipeline::B].execute_with_mut(&mut arg); | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "enum_pipeline_derive" | ||
description = "Provides derive macros for enum_pipeline." | ||
license = "mit" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.30" | ||
quote = "1.0.10" | ||
syn = {version = "1.0.80", features = ["full"]} |
Oops, something went wrong.