summaryrefslogtreecommitdiff
path: root/common/templates/rust/src/lib.rs
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/src/lib.rs
parentf9142a5822a4f212a3031b932cbf51b2d50344a8 (diff)
add flake templates
Diffstat (limited to 'common/templates/rust/src/lib.rs')
-rw-r--r--common/templates/rust/src/lib.rs33
1 files changed, 33 insertions, 0 deletions
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)
+}
+