commit cd7cf0434f173b3ac135f2678ab38d1bc82f19c4 from: msi date: Sun Nov 16 15:28:25 2025 UTC Add lib template commit - c722f8281d0f19080f19928a69de950c1472cf94 commit + cd7cf0434f173b3ac135f2678ab38d1bc82f19c4 blob - 8e02b112b51825a70f92d532464953a08ca1c7c9 blob + 1f0bdc5d8d60527216ca468236c6cfb3619cf0e1 --- Justfile +++ Justfile @@ -3,6 +3,7 @@ default: generate-all: just web + just lib web $CARGO_NAME="your name" $CARGO_EMAIL="author@example.com": rm -rv web-generated @@ -11,3 +12,10 @@ web $CARGO_NAME="your name" $CARGO_EMAIL="author@examp --define project-description="An example generated using the web template" \ --define use-gitserver=false +lib $CARGO_NAME="your name" $CARGO_EMAIL="author@example.com": + rm -rv lib-generated + cargo generate --path ./lib \ + --name lib-generated \ + --define project-description="An example generated using the lib template" \ + --define use-gitserver=false + blob - 1d9a3c42ede11a026b1a462108a3fca0b4ee414c blob + 7865e931341085021898aa54a18841eb6d1d7bb9 --- README.md +++ README.md @@ -21,3 +21,4 @@ cargo binstall cargo-generate -y | Name | Description | | ---------------------- | -------------------- | | [web](./web/README.md) | Axum render template | +| [lib](./lib/README.md) | Simple lib | blob - 58f9b7b1ef490c822549051ea418f7ee0d4925c5 blob + d61343292b8e3dcb2d1dd9dd76f375b3f29bb665 --- cargo-generate.toml +++ cargo-generate.toml @@ -4,4 +4,5 @@ cargo_generate_version = ">=0.23.0" sub_templates = [ "web", + "lib", ] blob - /dev/null blob + 03fd932487a0a72e1ecf7e67877b84ec6d08acb9 (mode 644) --- /dev/null +++ lib/README.md @@ -0,0 +1,2 @@ +# lib template + blob - /dev/null blob + d6c3cc68c2000702228b5bffcca841b63963bf2d (mode 644) --- /dev/null +++ lib/template/.editorconfig @@ -0,0 +1,11 @@ +# https://EditorConfig.org +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 + blob - /dev/null blob + 9fbc864de99bc6d43ce1b8d3e72609f3d862ec28 (mode 644) --- /dev/null +++ lib/template/.gitignore @@ -0,0 +1,2 @@ +target/ +tmp/ blob - /dev/null blob + 3aff51c5b56dec78c9a639db715ea6fc5ca591ef (mode 644) --- /dev/null +++ lib/template/.rustfmt.toml @@ -0,0 +1,19 @@ +style_edition = "2024" +max_width = 79 +# Make Rust more readable given most people have wide screens nowadays. +# This is also the setting used by [rustc](https://github.com/rust-lang/rust/blob/master/rustfmt.toml) +use_small_heuristics = "Max" + +# Use field initialize shorthand if possible +use_field_init_shorthand = true + +reorder_modules = true + +# All unstable features that we wish for +# unstable_features = true +# Provide a cleaner impl order +# reorder_impl_items = true +# Provide a cleaner import sort order +# group_imports = "StdExternalCrate" +# Group "use" statements by crate +# imports_granularity = "Crate" blob - /dev/null blob + 97b90540dbca0097c60085c1798f324005971f50 (mode 644) --- /dev/null +++ lib/template/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "{{project-name}}" +version = "0.1.0" + +authors = ["{{authors}}"] +description = "{{project-description}}" +edition = "2024" +license = "ISC" + +# +# lints +# + +[lints.rust] +absolute_paths_not_starting_with_crate = "warn" +non_ascii_idents = "warn" +tail_expr_drop_order = "warn" +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)', 'cfg(coverage_nightly)'] } +unit-bindings = "warn" +unsafe_op_in_unsafe_fn = "warn" +unused_unsafe = "warn" + +[lints.clippy] +all = { level = "warn", priority = -1 } + +# +# dep +# + +[dependencies] + + +# +# profiles +# + +[profile.dev] +debug = false + +[profile.test] +debug = false + +[profile.release-with-debug] +inherits = "release" +strip = false +debug = true + +[profile.coverage] +inherits = "release" +opt-level = 2 +codegen-units = 256 +lto = "thin" +debug-assertions = true +overflow-checks = true + +[profile.dev-no-debug-assertions] +inherits = "dev" +debug-assertions = false blob - /dev/null blob + d75154570f871d95f17777a70cb7cd7f874032a4 (mode 644) --- /dev/null +++ lib/template/Justfile @@ -0,0 +1,38 @@ +#!/usr/bin/env -S just --justfile + +_default: + @just --list -u + +# ==================== ALIASES ==================== +alias r := ci + +# ==================== SETUP & INITIALIZATION ==================== + +# Install git pre-commit hook to format files +install-hook: + echo -e "#!/bin/sh\njust fmt" > .git/hooks/pre-commit + chmod +x .git/hooks/pre-commit + +# ==================== CORE DEVELOPMENT ==================== + +watch +args='test --all': + cargo watch --clear --exec '{{args}}' + +ci: + cargo test --all + cargo clippy --all + cargo fmt --all -- --check + +# publish current master branch +publish: + #!/usr/bin/env bash + set -euxo pipefail + rm -rf tmp/release + git clone git@github.com + VERSION=`sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1` + cd tmp/release + git tag -a $VERSION -m "Release $VERSION" + git push origin $VERSION + cargo publish + cd ../.. + rm -rf tmp/release blob - /dev/null blob + 1d0d9244f35adb07ec6842c510b84af71c16b073 (mode 644) --- /dev/null +++ lib/template/LICENSE @@ -0,0 +1,13 @@ +Copyright (c) 2025 murilo ijanc' + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. blob - /dev/null blob + 3dcf61b571e7e37cb3e85018179e3d5e8667907e (mode 644) --- /dev/null +++ lib/template/README.md @@ -0,0 +1,11 @@ +# {{project-name}} + +## Run + +``` +RUST_LOG=debug cargo run +``` + +## License + +This project is licensed under the ISC license ([LICENSE](LICENSE) or http://opensource.org/licenses/ISC) blob - /dev/null blob + ec598e7aeffec900c5789433edba560252bac5d4 (mode 644) --- /dev/null +++ lib/template/cargo-generate.toml @@ -0,0 +1,5 @@ +[template] +cargo_generate_version = ">=0.23.0" + +[placeholders] +project-description = { type = "string", prompt = "Short description of the project", default = "An example generated using the simple template" } blob - /dev/null blob + f5ed9dcadcc66762474fb345944ca5d49b40de7f (mode 644) --- /dev/null +++ lib/template/dprint.json @@ -0,0 +1,12 @@ +{ + "markdown": { + }, + "toml": { + }, + "excludes": [ + ], + "plugins": [ + "https://plugins.dprint.dev/markdown-0.20.0.wasm", + "https://plugins.dprint.dev/toml-0.7.0.wasm" + ] +} blob - /dev/null blob + c1fb2d9c50e5911722bf536769d865074b8e72c5 (mode 644) --- /dev/null +++ lib/template/examples/simple.rs @@ -0,0 +1,20 @@ +// +// Copyright (c) 2025 murilo ijanc' +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// + +fn main() { + let msg = {{crate_name}}::hello("{{project-name}}"); + println!("{msg}"); +} blob - /dev/null blob + 02cb8fcb5372748d4273b6a49eceb78fbdb15ce6 (mode 644) --- /dev/null +++ lib/template/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +profile = "default" blob - /dev/null blob + aec5ec58309c3392973dd85bf559cc1ab13cd95d (mode 644) --- /dev/null +++ lib/template/src/lib.rs @@ -0,0 +1,33 @@ +// +// Copyright (c) 2025 murilo ijanc' +// +// Permission to use, copy, modify, and distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// + +pub fn hello(name: &str) -> String { + format!("Hello {name} =]") +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn check_hello() { + let name = "{{project-name}}"; + let msg = hello(name); + + assert!(msg.contains(name)) + } + +}