├── src
├── main.rs
└── lib.rs
├── .gitignore
├── tests
├── basic.rs
└── README.md
├── benches
├── example_bench.rs
└── README.md
├── rust-toolchain.toml
├── .github
├── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── question.yml
│ ├── feature-request.yml
│ └── bug-report.yml
├── dependabot.yml
└── workflows
│ ├── ci.yml
│ ├── format.yml
│ └── publish.yml
├── Cargo.toml
├── rustfmt.toml
├── docs
└── README.md
├── README.md
└── LICENSE
/src/main.rs:
--------------------------------------------------------------------------------
1 | // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | use ultralytics_template_rust::run_example;
4 |
5 | fn main() {
6 | println!("{}", run_example());
7 | }
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build artifacts
2 | /target
3 |
4 | # Cargo
5 | .cargo/
6 | Cargo.lock
7 |
8 | # Editor files
9 | .idea/
10 | .vscode/
11 |
12 | # OS cruft
13 | .DS_Store
14 | Thumbs.db
15 |
16 | # Coverage and tooling output
17 | coverage/
18 | *.profraw
19 | *.profdata
20 | llvm-cov-report/
21 |
22 | # Logs
23 | *.log
24 |
25 | # Benchmark results
26 | /target/criterion/
27 |
28 | # Cargo deny cache
29 | .cargo-deny/
30 |
--------------------------------------------------------------------------------
/tests/basic.rs:
--------------------------------------------------------------------------------
1 | // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | use ultralytics_template_rust::{add_numbers, run_example};
4 |
5 | #[test]
6 | fn add_numbers_handles_signed_values() {
7 | assert_eq!(add_numbers(2, 3), 5);
8 | assert_eq!(add_numbers(-1, 1), 0);
9 | assert_eq!(add_numbers(-1, -1), -2);
10 | }
11 |
12 | #[test]
13 | fn example_output_matches_cli() {
14 | assert_eq!(run_example(), "Added 1 + 2 = 3");
15 | }
16 |
--------------------------------------------------------------------------------
/benches/example_bench.rs:
--------------------------------------------------------------------------------
1 | // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | use criterion::{Criterion, black_box, criterion_group, criterion_main};
4 | use ultralytics_template_rust::add_numbers;
5 |
6 | fn benchmark_add_numbers(c: &mut Criterion) {
7 | c.bench_function("add_numbers", |b| {
8 | b.iter(|| add_numbers(black_box(100), black_box(200)))
9 | });
10 | }
11 |
12 | criterion_group!(benches, benchmark_add_numbers);
13 | criterion_main!(benches);
14 |
--------------------------------------------------------------------------------
/rust-toolchain.toml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | # Rust toolchain specification
4 | # See https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file
5 | # Using nightly to support unstable rustfmt features in rustfmt.toml
6 |
7 | [toolchain]
8 | channel = "nightly"
9 | components = ["rustfmt", "clippy", "rust-src", "rust-analyzer"]
10 | targets = ["x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"]
11 | profile = "default"
12 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | blank_issues_enabled: true
4 | contact_links:
5 | - name: 📄 Docs
6 | url: https://docs.ultralytics.com/
7 | about: Full Ultralytics Documentation
8 | - name: 💬 Forum
9 | url: https://community.ultralytics.com/
10 | about: Ask on Ultralytics Community Forum
11 | - name: 🎧 Discord
12 | url: https://ultralytics.com/discord
13 | about: Ask on Ultralytics Discord
14 | - name: ⌨️ Reddit
15 | url: https://reddit.com/r/ultralytics
16 | about: Ask on Ultralytics Subreddit
17 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | # Dependabot for package version updates
4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5 |
6 | version: 2
7 | updates:
8 | - package-ecosystem: cargo
9 | directory: "/"
10 | schedule:
11 | interval: weekly
12 | time: "04:00"
13 | open-pull-requests-limit: 10
14 | labels:
15 | - dependencies
16 |
17 | - package-ecosystem: github-actions
18 | directory: "/.github/workflows"
19 | schedule:
20 | interval: weekly
21 | time: "04:00"
22 | open-pull-requests-limit: 5
23 | labels:
24 | - dependencies
25 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | [package]
4 | name = "ultralytics-template-rust"
5 | version = "0.0.5"
6 | edition = "2024" # use the latest stable edition for new projects
7 | license = "AGPL-3.0-or-later"
8 | description = "Ultralytics Rust project template showcasing a minimal library and binary layout."
9 | repository = "https://github.com/ultralytics/template-rust"
10 | homepage = "https://www.ultralytics.com/"
11 | documentation = "https://docs.ultralytics.com"
12 | readme = "README.md"
13 | rust-version = "1.91" # edition 2024 requires Rust >= 1.85; pin to a current stable for CI
14 | keywords = ["ultralytics", "template", "ml", "ai", "yolo"]
15 | categories = ["development-tools", "science", "computer-vision"]
16 |
17 | [dependencies]
18 |
19 | [dev-dependencies]
20 | criterion = { version = "0.5", features = ["html_reports"] }
21 |
22 | [[bench]]
23 | name = "example_bench"
24 | harness = false
25 |
--------------------------------------------------------------------------------
/rustfmt.toml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | # Configuration for https://rust-lang.github.io/rustfmt/
4 | edition = "2024"
5 |
6 | # Enable unstable features (requires nightly)
7 | unstable_features = true
8 |
9 | # E.g. Foo { a, b, c }
10 | use_field_init_shorthand = true
11 |
12 | # Unstable options. These require a nightly compiler to use (cargo +nightly fmt).
13 |
14 | # We choose a wider comment width, as this tends to make comments more readable than truncating at
15 | # 80 characters.
16 | wrap_comments = true
17 | comment_width = 120
18 | format_code_in_doc_comments = true
19 |
20 | # `#[doc = "..."]` -> `/// ...`
21 | normalize_doc_attributes = true
22 |
23 | # We choose module granularity for imports as this tends to have the best balance between low
24 | # linecount while making it simple to understand diffs
25 | group_imports = "StdExternalCrate"
26 | imports_granularity = "Module"
27 |
28 | format_macro_matchers = true
29 |
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Tests Directory (`tests/`)
4 |
5 | This directory contains Rust integration tests for the Ultralytics template crate. Keeping tests close to user-facing
6 | behaviors helps ensure changes remain reliable and well-documented.
7 |
8 | ## 🧪 Overview
9 |
10 | - Uses standard [Cargo tests](https://doc.rust-lang.org/cargo/guide/tests.html) with Rust’s built-in test harness.
11 | - Organized to mirror the structure of the source code directory for easy navigation and reference.
12 | - Tests should be comprehensive, covering user-facing behavior, error handling, and edge cases.
13 |
14 | ## 🚀 Running Tests
15 |
16 | Run the full suite from the project root:
17 |
18 | ```bash
19 | cargo test
20 | ```
21 |
22 | To generate code coverage locally (Linux recommended):
23 |
24 | ```bash
25 | cargo llvm-cov --all-features --workspace --html
26 | ```
27 |
28 | ## ✨ Contributing
29 |
30 | We love contributions! If you find an issue or have an idea for improving the tests, please open an issue or submit a pull
31 | request. See our [Contributing Guide](https://docs.ultralytics.com/help/contributing/) for details.
32 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | name: CI
4 |
5 | permissions:
6 | contents: read
7 |
8 | on:
9 | push:
10 | branches: [main]
11 | pull_request:
12 | branches: [main]
13 | schedule:
14 | - cron: "0 0 * * *"
15 |
16 | jobs:
17 | test:
18 | runs-on: ${{ matrix.os }}
19 | strategy:
20 | fail-fast: false
21 | matrix:
22 | os: [ubuntu-latest, macos-latest, windows-latest]
23 |
24 | steps:
25 | - uses: actions/checkout@v6
26 |
27 | - name: Set up Rust
28 | uses: dtolnay/rust-toolchain@stable
29 |
30 | - name: Cache build artifacts
31 | uses: Swatinem/rust-cache@v2
32 |
33 | - name: Format
34 | run: cargo fmt --all -- --check
35 |
36 | - name: Clippy
37 | run: cargo clippy --all-targets --all-features -- -D warnings
38 |
39 | - name: Tests
40 | run: cargo test --all --all-features
41 |
42 | coverage:
43 | runs-on: ubuntu-latest
44 | needs: test
45 | steps:
46 | - uses: actions/checkout@v6
47 |
48 | - name: Set up Rust
49 | uses: dtolnay/rust-toolchain@stable
50 |
51 | - name: Cache build artifacts
52 | uses: Swatinem/rust-cache@v2
53 |
54 | - name: Install cargo-llvm-cov
55 | uses: taiki-e/install-action@v2
56 | with:
57 | tool: cargo-llvm-cov
58 |
59 | - name: Coverage
60 | run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
61 |
62 | - name: Upload coverage to Codecov
63 | uses: codecov/codecov-action@v5
64 | with:
65 | files: ./lcov.info
66 | token: ${{ secrets.CODECOV_TOKEN }}
67 | flags: template_coverage
68 |
--------------------------------------------------------------------------------
/src/lib.rs:
--------------------------------------------------------------------------------
1 | // Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
2 |
3 | use std::ops::Add;
4 |
5 | /// Adds two values together.
6 | ///
7 | /// The function works with any type that supports the `+` operator and is `Copy`, making it usable
8 | /// with common numeric primitives such as integers or floating-point numbers.
9 | ///
10 | /// # Examples
11 | /// ```
12 | /// use ultralytics_template_rust::add_numbers;
13 | ///
14 | /// let sum = add_numbers(1_i32, 2_i32);
15 | /// assert_eq!(sum, 3);
16 | ///
17 | /// let float_sum = add_numbers(1.5_f64, 2.0_f64);
18 | /// assert!((float_sum - 3.5_f64).abs() < f64::EPSILON);
19 | /// ```
20 | pub fn add_numbers(a: T, b: T) -> T
21 | where
22 | T: Add