diff --git a/.github/workflows/build-docs.yaml b/.github/workflows/build-docs.yaml new file mode 100644 index 0000000..c740f04 --- /dev/null +++ b/.github/workflows/build-docs.yaml @@ -0,0 +1,43 @@ +name: build, test, and deploy docs to GitHub Pages + +on: + push: + pull_request: + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: cargo build + run: cargo build + + - name: cargo test + run: cargo test + + build-docs: + needs: tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + components: rustfmt, rust-src + + - name: Build Documentation + uses: actions-rs/cargo@v1 + with: + command: doc + args: --all --no-deps + + - name: deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4.2.5 + with: + branch: gh-pages # The branch the action should deploy to. + folder: target/doc # The folder the action should deploy. diff --git a/README.md b/README.md index 1dc5678..dba86cf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Payment Engine +[](https://smallstepman.github.io/interview-task/interviewpuzzle/) ## Usage ### Run ```console @@ -13,14 +14,13 @@ cargo test - `csv` - csv parsing and building - `rust_decimal` - never handle money data with floats - `serde` - well, serialization and deserialization -- `trycmd` - integration test cases self-documented in a markdown file: [./tests/README.md](./tests/README.md) -- `typestate` - cool macro to skip on writing bunch of boilerplate code when using typestate pattern, and also, automatically provides [](awesome visualization of finite state machine it aids to produce) +- `trycmd` - e2e tests, with test cases self-documented in a markdown file: [./tests/README.md](./tests/README.md) +- `typestate` - cool macro to skip on writing bunch of boilerplate code when using typestate pattern, and also, automatically provides [awesome UML visualization](https://smallstepman.github.io/interview-task/interviewpuzzle/ledger/transaction/index.html) of finite state machine it aids to produce ## Unsafe stuff -- incomplete featured enabled with a flag `#![feature(type_changing_struct_update)]` ([https://rust-lang.github.io/rfcs/2528-type-changing-struct-update-syntax.html](RFC2528)) enabled me to use syntax for destructuring structs between each other in typestate context (ok to use in this toy project) +- Nada ## Missed out on some things - 100% test-coverage - deep analysis and correct implementation of all business use cases and edge cases -- code comments, and CI/CD'ing `cargo doc` output into GitHub Pages with GitHub Actions - beautiful error logs diff --git a/src/ledger.rs b/src/ledger.rs index 7215d92..fdf8131 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -119,8 +119,14 @@ impl DefaultState for Tx { } fn dispute(self) -> Tx { Tx:: { + // repetition easliy avoidable with `..self` + // but will have to wait once this is stable + // https://github.com/rust-lang/rust/issues/86555 state: Disputed, - ..self + amount: self.amount, + client_id: self.client_id, + id: self.id, + tx_type: self.tx_type, } } } @@ -129,13 +135,19 @@ impl DisputedState for Tx { fn resolve(self) -> Tx { Tx:: { state: Default, - ..self + amount: self.amount, + client_id: self.client_id, + id: self.id, + tx_type: self.tx_type, } } fn chargeback(self) -> Tx { Tx:: { state: Chargebacked, - ..self + amount: self.amount, + client_id: self.client_id, + id: self.id, + tx_type: self.tx_type, } } } diff --git a/src/main.rs b/src/main.rs index 457e9b0..c58cfd0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,3 @@ -#![feature(type_changing_struct_update)] -#![allow(incomplete_features)] - mod utils; // importing as a first item to register the macro before everything else pub(crate) mod core;