use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
#[derive(Debug, Deserialize, JsonSchema)]
pub struct Input {
pub text: String,
}
#[derive(Debug, Serialize, JsonSchema)]
pub struct Output {
pub characters: usize,
pub words: usize,
pub lines: usize,
}
pub struct TextWordCount;
impl TextWordCount {
pub const MODULE_ID: &'static str = "text.wordcount";
pub const DESCRIPTION: &'static str =
"Count words, characters, and lines in a text string";
pub fn execute(input: Input) -> Output {
let text = &input.text;
Output {
characters: text.chars().count(),
words: text.split_whitespace().count(),
lines: text.lines().count(),
}
}
}
fn main() {
let input = Input {
text: "hello world from apcore".to_string(),
};
let output = TextWordCount::execute(input);
println!("{}", serde_json::to_string_pretty(&output).unwrap());
}