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/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ common/templates/rust/src/main.rs | 6 ++++++ 2 files changed, 39 insertions(+) create mode 100644 common/templates/rust/src/lib.rs create mode 100644 common/templates/rust/src/main.rs (limited to 'common/templates/rust/src') 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