From dfc8cf908da3e4e2c3e95bbd6190df4e3eb96095 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Fri, 12 Jan 2024 15:54:39 +0100 Subject: [PATCH] Write plugin to be used in app --- src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3e863e8..7622dde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,3 +4,15 @@ use extism_pdk::*; pub fn greet(name: String) -> FnResult { Ok(format!("Hello, {}!", name)) } + +#[plugin_fn] +pub fn count_vowels(sentence: String) -> FnResult { + let vowels = "aeiouAEIOU"; + let mut vowel_count = 0; + for c in sentence.chars() { + if vowels.contains(c) { + vowel_count += 1; + } + } + Ok(format!("{vowel_count}")) +}