Skip to content

Commit 229aba0

Browse files
committed
feat: add calculator, price list and info page
0 parents  commit 229aba0

File tree

21 files changed

+4921
-0
lines changed

21 files changed

+4921
-0
lines changed

.dockerignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Rust
7+
target/
8+
**/*.rs.bk
9+
*.pdb
10+
11+
# IDE
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.swo
16+
*~
17+
18+
# OS
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Docs
23+
README.md
24+
LICENSE
25+
*.md
26+
27+
# CI/CD
28+
.github/
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
description: 'Rust programming language coding conventions and best practices'
3+
applyTo: '**/*.rs'
4+
---
5+
6+
# Rust Coding Conventions and Best Practices
7+
8+
Follow idiomatic Rust practices and community standards when writing Rust code.
9+
10+
These instructions are based on [The Rust Book](https://doc.rust-lang.org/book/), [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/), [RFC 430 naming conventions](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md), and the broader Rust community at [users.rust-lang.org](https://users.rust-lang.org).
11+
12+
## General Instructions
13+
14+
- Always prioritize readability, safety, and maintainability.
15+
- Use strong typing and leverage Rust's ownership system for memory safety.
16+
- Break down complex functions into smaller, more manageable functions.
17+
- For algorithm-related code, include explanations of the approach used.
18+
- Write code with good maintainability practices, including comments on why certain design decisions were made.
19+
- Handle errors gracefully using `Result<T, E>` and provide meaningful error messages.
20+
- For external dependencies, mention their usage and purpose in documentation.
21+
- Use consistent naming conventions following [RFC 430](https://github.com/rust-lang/rfcs/blob/master/text/0430-finalizing-naming-conventions.md).
22+
- Write idiomatic, safe, and efficient Rust code that follows the borrow checker's rules.
23+
- Ensure code compiles without warnings.
24+
25+
## Patterns to Follow
26+
27+
- Use modules (`mod`) and public interfaces (`pub`) to encapsulate logic.
28+
- Handle errors properly using `?`, `match`, or `if let`.
29+
- Use `serde` for serialization and `thiserror` or `anyhow` for custom errors.
30+
- Implement traits to abstract services or external dependencies.
31+
- Structure async code using `async/await` and `tokio` or `async-std`.
32+
- Prefer enums over flags and states for type safety.
33+
- Use builders for complex object creation.
34+
- Split binary and library code (`main.rs` vs `lib.rs`) for testability and reuse.
35+
- Use `rayon` for data parallelism and CPU-bound tasks.
36+
- Use iterators instead of index-based loops as they're often faster and safer.
37+
- Use `&str` instead of `String` for function parameters when you don't need ownership.
38+
- Prefer borrowing and zero-copy operations to avoid unnecessary allocations.
39+
40+
### Ownership, Borrowing, and Lifetimes
41+
42+
- Prefer borrowing (`&T`) over cloning unless ownership transfer is necessary.
43+
- Use `&mut T` when you need to modify borrowed data.
44+
- Explicitly annotate lifetimes when the compiler cannot infer them.
45+
- Use `Rc<T>` for single-threaded reference counting and `Arc<T>` for thread-safe reference counting.
46+
- Use `RefCell<T>` for interior mutability in single-threaded contexts and `Mutex<T>` or `RwLock<T>` for multi-threaded contexts.
47+
48+
## Patterns to Avoid
49+
50+
- Don't use `unwrap()` or `expect()` unless absolutely necessary—prefer proper error handling.
51+
- Avoid panics in library code—return `Result` instead.
52+
- Don't rely on global mutable state—use dependency injection or thread-safe containers.
53+
- Avoid deeply nested logic—refactor with functions or combinators.
54+
- Don't ignore warnings—treat them as errors during CI.
55+
- Avoid `unsafe` unless required and fully documented.
56+
- Don't overuse `clone()`, use borrowing instead of cloning unless ownership transfer is needed.
57+
- Avoid premature `collect()`, keep iterators lazy until you actually need the collection.
58+
- Avoid unnecessary allocations—prefer borrowing and zero-copy operations.
59+
60+
## Code Style and Formatting
61+
62+
- Follow the Rust Style Guide and use `rustfmt` for automatic formatting.
63+
- Keep lines under 100 characters when possible.
64+
- Place function and struct documentation immediately before the item using `///`.
65+
- Use `cargo clippy` to catch common mistakes and enforce best practices.
66+
67+
## Error Handling
68+
69+
- Use `Result<T, E>` for recoverable errors and `panic!` only for unrecoverable errors.
70+
- Prefer `?` operator over `unwrap()` or `expect()` for error propagation.
71+
- Create custom error types using `thiserror` or implement `std::error::Error`.
72+
- Use `Option<T>` for values that may or may not exist.
73+
- Provide meaningful error messages and context.
74+
- Error types should be meaningful and well-behaved (implement standard traits).
75+
- Validate function arguments and return appropriate errors for invalid input.
76+
77+
## API Design Guidelines
78+
79+
### Common Traits Implementation
80+
Eagerly implement common traits where appropriate:
81+
- `Copy`, `Clone`, `Eq`, `PartialEq`, `Ord`, `PartialOrd`, `Hash`, `Debug`, `Display`, `Default`
82+
- Use standard conversion traits: `From`, `AsRef`, `AsMut`
83+
- Collections should implement `FromIterator` and `Extend`
84+
- Note: `Send` and `Sync` are auto-implemented by the compiler when safe; avoid manual implementation unless using `unsafe` code
85+
86+
### Type Safety and Predictability
87+
- Use newtypes to provide static distinctions
88+
- Arguments should convey meaning through types; prefer specific types over generic `bool` parameters
89+
- Use `Option<T>` appropriately for truly optional values
90+
- Functions with a clear receiver should be methods
91+
- Only smart pointers should implement `Deref` and `DerefMut`
92+
93+
### Future Proofing
94+
- Use sealed traits to protect against downstream implementations
95+
- Structs should have private fields
96+
- Functions should validate their arguments
97+
- All public types must implement `Debug`
98+
99+
## Testing and Documentation
100+
101+
- Write comprehensive unit tests using `#[cfg(test)]` modules and `#[test]` annotations.
102+
- Use test modules alongside the code they test (`mod tests { ... }`).
103+
- Write integration tests in `tests/` directory with descriptive filenames.
104+
- Write clear and concise comments for each function, struct, enum, and complex logic.
105+
- Ensure functions have descriptive names and include comprehensive documentation.
106+
- Document all public APIs with rustdoc (`///` comments) following the [API Guidelines](https://rust-lang.github.io/api-guidelines/).
107+
- Use `#[doc(hidden)]` to hide implementation details from public documentation.
108+
- Document error conditions, panic scenarios, and safety considerations.
109+
- Examples should use `?` operator, not `unwrap()` or deprecated `try!` macro.
110+
111+
## Project Organization
112+
113+
- Use semantic versioning in `Cargo.toml`.
114+
- Include comprehensive metadata: `description`, `license`, `repository`, `keywords`, `categories`.
115+
- Use feature flags for optional functionality.
116+
- Organize code into modules using `mod.rs` or named files.
117+
- Keep `main.rs` or `lib.rs` minimal - move logic to modules.
118+
119+
## Quality Checklist
120+
121+
Before publishing or reviewing Rust code, ensure:
122+
123+
### Core Requirements
124+
- [ ] **Naming**: Follows RFC 430 naming conventions
125+
- [ ] **Traits**: Implements `Debug`, `Clone`, `PartialEq` where appropriate
126+
- [ ] **Error Handling**: Uses `Result<T, E>` and provides meaningful error types
127+
- [ ] **Documentation**: All public items have rustdoc comments with examples
128+
- [ ] **Testing**: Comprehensive test coverage including edge cases
129+
130+
### Safety and Quality
131+
- [ ] **Safety**: No unnecessary `unsafe` code, proper error handling
132+
- [ ] **Performance**: Efficient use of iterators, minimal allocations
133+
- [ ] **API Design**: Functions are predictable, flexible, and type-safe
134+
- [ ] **Future Proofing**: Private fields in structs, sealed traits where appropriate
135+
- [ ] **Tooling**: Code passes `cargo fmt`, `cargo clippy`, and `cargo test`
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Deploy to GitHub Container Registry
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- "v*"
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
workflow_dispatch:
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: ${{ github.repository }}
19+
20+
jobs:
21+
build-and-push:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Log in to GitHub Container Registry
35+
uses: docker/login-action@v3
36+
with:
37+
registry: ${{ env.REGISTRY }}
38+
username: ${{ github.actor }}
39+
password: ${{ secrets.GITHUB_TOKEN }}
40+
41+
- name: Extract metadata (tags, labels) for Docker
42+
id: meta
43+
uses: docker/metadata-action@v5
44+
with:
45+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=semver,pattern={{version}}
50+
type=semver,pattern={{major}}.{{minor}}
51+
type=semver,pattern={{major}}
52+
type=sha,prefix={{branch}}-
53+
type=raw,value=latest,enable={{is_default_branch}}
54+
55+
- name: Build and push Docker image
56+
uses: docker/build-push-action@v5
57+
with:
58+
context: .
59+
push: true
60+
tags: ${{ steps.meta.outputs.tags }}
61+
labels: ${{ steps.meta.outputs.labels }}
62+
cache-from: type=gha
63+
cache-to: type=gha,mode=max
64+
platforms: linux/amd64,linux/arm64
65+
66+
- name: Generate artifact attestation
67+
uses: actions/attest-build-provenance@v1
68+
with:
69+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
70+
subject-digest: ${{ steps.build.outputs.digest }}
71+
push-to-registry: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/dist

0 commit comments

Comments
 (0)