Skip to content

Commit 3320008

Browse files
committed
add: text hook
1 parent ffc4bd8 commit 3320008

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ use brack_pdk_rs::metadata::Metadata;
33
use document::metadata_document;
44
use extism_pdk::{plugin_fn, FnResult, Json};
55
use stmt::metadata_stmt;
6+
use text::metadata_text;
67

78
pub mod document;
89
pub mod bold;
910
pub mod stmt;
11+
pub mod text;
1012

1113
#[plugin_fn]
1214
pub fn get_metadata() -> FnResult<Json<Vec<Metadata>>> {
1315
let mut metadata = Vec::new();
1416
metadata.push(metadata_bold());
1517
metadata.push(metadata_document());
1618
metadata.push(metadata_stmt());
19+
metadata.push(metadata_text());
1720
Ok(Json(metadata))
1821
}

src/text.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use brack_pdk_rs::{metadata::Metadata, types::Type, values::Value};
2+
use extism_pdk::{plugin_fn, FnResult, Json, WithReturnCode};
3+
4+
pub(crate) fn metadata_text() -> Metadata {
5+
Metadata {
6+
command_name: "text".to_string(),
7+
call_name: "text".to_string(),
8+
argument_types: vec![("text".to_string(), Type::TInline)],
9+
return_type: Type::TInline,
10+
}
11+
}
12+
13+
#[plugin_fn]
14+
pub fn text(Json(args): Json<Vec<Value>>) -> FnResult<String> {
15+
if args.len() != 1 {
16+
return Err(WithReturnCode::new(anyhow::anyhow!("text failed"), 1));
17+
}
18+
let text = match &args[0] {
19+
Value::Text(t) => t,
20+
_ => {
21+
return Err(WithReturnCode::new(
22+
anyhow::anyhow!("text must be Value::Text"),
23+
1,
24+
))
25+
}
26+
};
27+
Ok(format!("{{\"t\": \"Str\", \"c\": \"{}\"}}", text))
28+
}

0 commit comments

Comments
 (0)