aboutsummaryrefslogtreecommitdiffstats
path: root/lib/template
diff options
context:
space:
mode:
authormsi2025-11-16 12:28:25 -0300
committermsi2025-11-16 12:28:25 -0300
commitcd7cf0434f173b3ac135f2678ab38d1bc82f19c4 (patch)
tree9171ea3384d62217fe29d906b43fca9ba9e693c3 /lib/template
parentc722f8281d0f19080f19928a69de950c1472cf94 (diff)
downloadtemplates-cd7cf0434f173b3ac135f2678ab38d1bc82f19c4.tar.gz
Add lib template
Diffstat (limited to 'lib/template')
-rw-r--r--lib/template/.editorconfig11
-rw-r--r--lib/template/.gitignore2
-rw-r--r--lib/template/.rustfmt.toml19
-rw-r--r--lib/template/Cargo.toml58
-rw-r--r--lib/template/Justfile38
-rw-r--r--lib/template/LICENSE13
-rw-r--r--lib/template/README.md11
-rw-r--r--lib/template/cargo-generate.toml5
-rw-r--r--lib/template/dprint.json12
-rw-r--r--lib/template/examples/simple.rs20
-rw-r--r--lib/template/rust-toolchain.toml3
-rw-r--r--lib/template/src/lib.rs33
12 files changed, 225 insertions, 0 deletions
diff --git a/lib/template/.editorconfig b/lib/template/.editorconfig
new file mode 100644
index 0000000..d6c3cc6
--- /dev/null
+++ b/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
+
diff --git a/lib/template/.gitignore b/lib/template/.gitignore
new file mode 100644
index 0000000..9fbc864
--- /dev/null
+++ b/lib/template/.gitignore
@@ -0,0 +1,2 @@
+target/
+tmp/
diff --git a/lib/template/.rustfmt.toml b/lib/template/.rustfmt.toml
new file mode 100644
index 0000000..3aff51c
--- /dev/null
+++ b/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"
diff --git a/lib/template/Cargo.toml b/lib/template/Cargo.toml
new file mode 100644
index 0000000..97b9054
--- /dev/null
+++ b/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
diff --git a/lib/template/Justfile b/lib/template/Justfile
new file mode 100644
index 0000000..d751545
--- /dev/null
+++ b/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
diff --git a/lib/template/LICENSE b/lib/template/LICENSE
new file mode 100644
index 0000000..1d0d924
--- /dev/null
+++ b/lib/template/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
+
+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.
diff --git a/lib/template/README.md b/lib/template/README.md
new file mode 100644
index 0000000..3dcf61b
--- /dev/null
+++ b/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)
diff --git a/lib/template/cargo-generate.toml b/lib/template/cargo-generate.toml
new file mode 100644
index 0000000..ec598e7
--- /dev/null
+++ b/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" }
diff --git a/lib/template/dprint.json b/lib/template/dprint.json
new file mode 100644
index 0000000..f5ed9dc
--- /dev/null
+++ b/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"
+ ]
+}
diff --git a/lib/template/examples/simple.rs b/lib/template/examples/simple.rs
new file mode 100644
index 0000000..c1fb2d9
--- /dev/null
+++ b/lib/template/examples/simple.rs
@@ -0,0 +1,20 @@
+//
+// Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
+//
+// 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}");
+}
diff --git a/lib/template/rust-toolchain.toml b/lib/template/rust-toolchain.toml
new file mode 100644
index 0000000..02cb8fc
--- /dev/null
+++ b/lib/template/rust-toolchain.toml
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "stable"
+profile = "default"
diff --git a/lib/template/src/lib.rs b/lib/template/src/lib.rs
new file mode 100644
index 0000000..aec5ec5
--- /dev/null
+++ b/lib/template/src/lib.rs
@@ -0,0 +1,33 @@
+//
+// Copyright (c) 2025 murilo ijanc' <murilo@ijanc.org>
+//
+// 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))
+ }
+
+}