DenoDDeno
Powered by
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
}
#[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
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
#[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
}
#[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
71 | async fn op_fetch2(#[string] req: String) -> #[string] String {
   |                                              ^ expected type
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

intercept an op rust-side and call the original fn
robtfmRrobtfm / help
2y ago
In Fresh, how do I return a JSON response in a middleware?
TheYuriGTTheYuriG / help
3y ago
Return lazy struct fields from Op
NickNNick / help
3y ago
How to send an enum value from Rust to Deno
furiouzzFfuriouzz / help
3y ago