Skip to content

Commit 048133e

Browse files
authored
The third revision (#3)
1 parent 93649aa commit 048133e

File tree

9 files changed

+88
-11
lines changed

9 files changed

+88
-11
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@
5151
*.out filter=lfs diff=lfs merge=lfs -text
5252
*.a filter=lfs diff=lfs merge=lfs -text
5353
*.o filter=lfs diff=lfs merge=lfs -text
54+
55+
# Exclude files from language stats (GitHub Linguist)
56+
*.ipynb linguist-vendored

Cargo.toml

+38-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "template-rust-project"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
description = "A template for Rust projects"
55
repository = "https://github.com/habedi/template-rust-project"
66
license = "MIT OR Apache-2.0"
@@ -9,8 +9,24 @@ keywords = ["project-template", "rust", "library", "application"]
99
authors = ["Hassan Abedi <[email protected]>"]
1010
homepage = "https://github.com/habedi/template-rust-project"
1111
documentation = "https://docs.rs/template-rust-project"
12-
#categories = ["development-tools"]
12+
categories = ["development-tools"]
1313
edition = "2021"
14+
rust-version = "1.83"
15+
16+
[workspace]
17+
members = []
18+
19+
resolver = "2"
20+
21+
include = [
22+
"assets/**/*",
23+
"docs/**/*",
24+
"src/**/*",
25+
"Cargo.toml",
26+
"README.md",
27+
"LICENSE-MIT",
28+
"LICENSE-APACHE"
29+
]
1430

1531
[lib]
1632
name = "template_rust_project"
@@ -20,9 +36,26 @@ path = "src/lib.rs"
2036
name = "template-rust-project"
2137
path = "src/main.rs"
2238

39+
[features]
40+
default = [] # No features enabled by default
41+
binaries = []
42+
2343
[dependencies]
24-
clap = "4.5.27"
25-
log = "0.4.25"
44+
ctor = "0.2.9"
2645
tracing = "0.1.41"
46+
tracing-subscriber = "0.3.19"
47+
48+
[dev-dependencies]
49+
criterion = { version = "0.5", features = ["html_reports"] }
50+
51+
[[bench]]
52+
name = "project_benchmarks"
53+
harness = false
54+
55+
[profile.release]
56+
strip = "symbols"
57+
codegen-units = 1
58+
lto = true
2759

28-
[dev-dependencies]
60+
[profile.bench]
61+
debug = true

Makefile

+18-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PKG = github.com/habedi/template-rust-project
33
BINARY_NAME = $(or $(PROJ_BINARY), $(notdir $(PKG)))
44
BINARY = target/release/$(BINARY_NAME)
55
PATH := /snap/bin:$(PATH)
6+
DEBUG_PROJ = 1
67

78
# Default target
89
.DEFAULT_GOAL := help
@@ -19,22 +20,22 @@ format: ## Format Rust files
1920
.PHONY: test
2021
test: format ## Run tests
2122
@echo "Running tests..."
22-
cargo test -- --nocapture
23+
DEBUG_PROJ=$(DEBUG_PROJ) cargo test -- --nocapture
2324

2425
.PHONY: coverage
2526
coverage: format ## Generate test coverage report
2627
@echo "Generating test coverage report..."
27-
cargo tarpaulin --out Xml --out Html
28+
DEBUG_PROJ=$(DEBUG_PROJ) cargo tarpaulin --out Xml --out Html
2829

2930
.PHONY: build
3031
build: format ## Build the binary for the current platform
3132
@echo "Building the project..."
32-
cargo build --release
33+
DEBUG_PROJ=$(DEBUG_PROJ) cargo build --release
3334

3435
.PHONY: run
3536
run: build ## Build and run the binary
3637
@echo "Running the $(BINARY) binary..."
37-
./$(BINARY)
38+
DEBUG_PROJ=$(DEBUG_PROJ) ./$(BINARY)
3839

3940
.PHONY: clean
4041
clean: ## Remove generated and temporary files
@@ -54,13 +55,24 @@ install-deps: install-snap ## Install development dependencies
5455
@echo "Installing dependencies..."
5556
rustup component add rustfmt clippy
5657
cargo install cargo-tarpaulin
58+
cargo install cargo-audit
5759

5860
.PHONY: lint
5961
lint: format ## Run linters on Rust files
6062
@echo "Linting Rust files..."
61-
cargo clippy -- -D warnings
63+
DEBUG_PROJ=$(DEBUG_PROJ) cargo clippy -- -D warnings
6264

6365
.PHONY: publish
6466
publish: ## Publish the package to crates.io (requires CARGO_REGISTRY_TOKEN to be set)
6567
@echo "Publishing the package to Cargo registry..."
66-
cargo publish --token $(CARGO_REGISTRY_TOKEN)
68+
cargo publish --token $(CARGO_REGISTRY_TOKEN)
69+
70+
.PHONY: bench
71+
bench: ## Run benchmarks
72+
@echo "Running benchmarks..."
73+
DEBUG_PROJ=$(DEBUG_PROJ) cargo bench
74+
75+
.PHONY: audit
76+
audit: ## Run security audit on Rust dependencies
77+
@echo "Running security audit..."
78+
cargo audit

benches/project_benchmarks.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
3+
fn benchmark_fun(_c: &mut Criterion) {
4+
// Your benchmarking code here
5+
}
6+
7+
criterion_group!(benches, benchmark_fun,);
8+
criterion_main!(benches);

src/cli.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::ffi::OsString;
2+
use tracing::error;
23

34
pub fn run(args: impl IntoIterator<Item = OsString>) -> Result<(), i32> {
45
let _args: Vec<OsString> = args.into_iter().collect();
56
// Your implementation here
67
// Expecting at least 2 arguments
78
if _args.len() < 2 {
9+
error!("Expecting at least 2 arguments");
810
return Err(1);
911
}
1012
Ok(())

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod cli;
2+
pub mod logging;

src/logging.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use ctor::ctor;
2+
use tracing::Level;
3+
use tracing_subscriber;
4+
5+
#[ctor]
6+
fn set_debug_level() {
7+
// If DEBUG_PROJ is not set or set to false, disable logging. Otherwise, enable logging
8+
if std::env::var("DEBUG_PROJ").map_or(true, |v| v == "0" || v == "false" || v.is_empty()) {
9+
// Disable logging
10+
} else {
11+
tracing_subscriber::fmt()
12+
.with_max_level(Level::DEBUG)
13+
.init();
14+
}
15+
16+
//println!("DEBUG_PROJ: {:?}", std::env::var("DEBUG_PROJ"));
17+
}

tests/.gitkeep

Whitespace-only changes.

tests/integration_tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)