A Frickn ChicknA
Denoβ€’2y agoβ€’
4 replies
A Frickn Chickn

How do you define an op in rust to return a string?

#[deno_core::op2(async)]
async fn op_fetch(#[string] req: String) -> String {
    async { "hello".to_string() }.await
}


fails to compile

70 | #[deno_core::op2(async)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: Failed to parse #[op2]:
            - Failed to parse signature
            - Invalid return type
            - Invalid return type
            - Missing a #[string] attribute for type: String


https://github.com/denoland/deno_core/blob/main/ops/op2/README.md#return-values this guide says I should mark string with #[string] String, however this also doesn't compile.

#[deno_core::op2(async)]
async fn op_fetch(#[string] req: String) -> #[string] String {
    async { "hello".to_string() }.await
}


71 | async fn op_fetch2(#[string] req: String) -> #[string] String {
   |                                              ^ expected type
Was this page helpful?