summaryrefslogtreecommitdiff
path: root/common/templates/rust
diff options
context:
space:
mode:
authorbrustybee <bee@4d2.org>2026-03-19 23:43:21 +0530
committerbrustybee <bee@4d2.org>2026-03-19 23:43:21 +0530
commit9d2256adddbb830d33119a5e01e3fad6b4b0652b (patch)
tree958e1de443a6d59a9b09716ba5815c52bfb7bfb3 /common/templates/rust
parentf9142a5822a4f212a3031b932cbf51b2d50344a8 (diff)
add flake templates
Diffstat (limited to 'common/templates/rust')
-rw-r--r--common/templates/rust/.envrc1
-rw-r--r--common/templates/rust/.gitignore29
-rw-r--r--common/templates/rust/Cargo.lock7
-rw-r--r--common/templates/rust/Cargo.toml14
-rw-r--r--common/templates/rust/flake.nix50
-rw-r--r--common/templates/rust/src/lib.rs33
-rw-r--r--common/templates/rust/src/main.rs6
7 files changed, 140 insertions, 0 deletions
diff --git a/common/templates/rust/.envrc b/common/templates/rust/.envrc
new file mode 100644
index 0000000..3550a30
--- /dev/null
+++ b/common/templates/rust/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/common/templates/rust/.gitignore b/common/templates/rust/.gitignore
new file mode 100644
index 0000000..e8cf9a0
--- /dev/null
+++ b/common/templates/rust/.gitignore
@@ -0,0 +1,29 @@
+# Generated by Cargo
+# will have compiled files and executables
+debug
+target
+
+.direnv
+
+# These are backup files generated by rustfmt
+**/*.rs.bk
+
+# MSVC Windows builds of rustc generate these, which store debugging information
+*.pdb
+
+# Generated by cargo mutants
+# Contains mutation testing data
+**/mutants.out*/
+
+# RustRover
+# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
+# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
+# and can be added to the global gitignore or merged into this file. For a more nuclear
+# option (not recommended) you can uncomment the following to ignore the entire idea folder.
+#.idea/
+
+
+# Added by cargo
+
+/target
+
diff --git a/common/templates/rust/Cargo.lock b/common/templates/rust/Cargo.lock
new file mode 100644
index 0000000..c87dd44
--- /dev/null
+++ b/common/templates/rust/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "rust-project"
+version = "0.1.0"
diff --git a/common/templates/rust/Cargo.toml b/common/templates/rust/Cargo.toml
new file mode 100644
index 0000000..5ab6a6c
--- /dev/null
+++ b/common/templates/rust/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "rust-project"
+version = "0.1.0"
+edition = "2024"
+description = """
+my rust project
+"""
+repository = ""
+license = ""
+
+[workspace]
+members = []
+
+[dependencies]
diff --git a/common/templates/rust/flake.nix b/common/templates/rust/flake.nix
new file mode 100644
index 0000000..afe2601
--- /dev/null
+++ b/common/templates/rust/flake.nix
@@ -0,0 +1,50 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ naersk.url = "github:nix-community/naersk";
+ naersk.inputs.nixpkgs.follows = "nixpkgs";
+ };
+
+ outputs =
+ {
+ self,
+ nixpkgs,
+ naersk,
+ ...
+ }:
+ let
+ inherit (nixpkgs) lib;
+ forAllSystems = lib.genAttrs lib.systems.flakeExposed;
+ in
+ {
+ devShells = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ in
+ {
+ default = pkgs.mkShell {
+ buildInputs = with pkgs; [
+ cargo
+ clippy
+ rustc
+ rustfmt
+ rust-analyzer
+ ];
+ RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
+ };
+ }
+ );
+
+ packages = forAllSystems (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ naersk-lib = pkgs.callPackage naersk { };
+ in
+ {
+ default = naersk-lib.buildPackage self;
+ }
+ );
+ };
+}
diff --git a/common/templates/rust/src/lib.rs b/common/templates/rust/src/lib.rs
new file mode 100644
index 0000000..ee5d017
--- /dev/null
+++ b/common/templates/rust/src/lib.rs
@@ -0,0 +1,33 @@
+use std::any::type_name;
+
+pub fn hello_world(action: &str) {
+ // Every function in Rust has a unique, unnameable type.
+ // we define a tiny helper to extract that type's name.
+ fn get_type_name<T>(_: T) -> &'static str {
+ type_name::<T>()
+ }
+
+ // This gives us "current_crate::hello_world"
+ let full_path = get_type_name(hello_world);
+
+ // We transform the string entirely through a lazy iterator pipeline.
+ let formatted: String = full_path
+ .split("::")
+ .last()
+ .unwrap_or("")
+ .split('_')
+ .map(|word| {
+ // Capitalize the first letter and chain the rest
+ let mut chars = word.chars();
+ chars
+ .next()
+ .map(|f| f.to_uppercase().collect::<String>() + chars.as_str())
+ .unwrap_or_default()
+ })
+ .collect::<Vec<_>>()
+ .join(", ")
+ + "!";
+
+ println!("{}", formatted)
+}
+
diff --git a/common/templates/rust/src/main.rs b/common/templates/rust/src/main.rs
new file mode 100644
index 0000000..629b4b1
--- /dev/null
+++ b/common/templates/rust/src/main.rs
@@ -0,0 +1,6 @@
+use rust_project::hello_world;
+
+fn main() {
+ hello_world("print");
+}
+