From 9d2256adddbb830d33119a5e01e3fad6b4b0652b Mon Sep 17 00:00:00 2001 From: brustybee Date: Thu, 19 Mar 2026 23:43:21 +0530 Subject: add flake templates --- common/templates/rust/.envrc | 1 + common/templates/rust/.gitignore | 29 +++++++++++++++++++++++ common/templates/rust/Cargo.lock | 7 ++++++ common/templates/rust/Cargo.toml | 14 +++++++++++ common/templates/rust/flake.nix | 50 +++++++++++++++++++++++++++++++++++++++ common/templates/rust/src/lib.rs | 33 ++++++++++++++++++++++++++ common/templates/rust/src/main.rs | 6 +++++ 7 files changed, 140 insertions(+) create mode 100644 common/templates/rust/.envrc create mode 100644 common/templates/rust/.gitignore create mode 100644 common/templates/rust/Cargo.lock create mode 100644 common/templates/rust/Cargo.toml create mode 100644 common/templates/rust/flake.nix create mode 100644 common/templates/rust/src/lib.rs create mode 100644 common/templates/rust/src/main.rs (limited to 'common/templates/rust') 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) -> &'static str { + type_name::() + } + + // 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::() + chars.as_str()) + .unwrap_or_default() + }) + .collect::>() + .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"); +} + -- cgit v1.3.1