Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write an RFD for a Rust SDK proc-macro crate #447

Open
j-lanson opened this issue Sep 24, 2024 · 0 comments
Open

Write an RFD for a Rust SDK proc-macro crate #447

j-lanson opened this issue Sep 24, 2024 · 0 comments
Assignees
Labels
product: rust-sdk Relates to the Rust plugin SDK type: enhancement New feature or request

Comments

@j-lanson
Copy link
Collaborator

We could further simplify writing plugins by having a proc-macro that we can use to tag functions as "query endpoints" and then extract their name, input type / output type to produce a struct implementing Query.

impl Serialize for InputObject { ... }
impl Serialize for OutputObject { ... }

#[this_is_a_sdk_query(default = true)]
async fn query_endpoint(engine: &mut PluginEngine, input: InputObject) -> Result<OutputObject>

-->

  1. generate Schemars json objects for InputObject / OutputObject

struct ThisIsAnSdkQuery {}
impl Query for ThisIsAnSdkQuery {
   fn input_schema(&self) -> JsonSchema { return generated Schemars object };
   fn input_schema(&self) -> JsonSchema { return generated Schemars object };
   async fn run(&self, engine: &mut PluginEngine, input: JsonValue) -> Result<JsonValue> {
      let input: InputObject = serde_json::from_value(input)?;
      let res = query_endpoint(engine, input);
      res.map(|v| serde_json::to_value(v))
   }
}

And create a NamedStruct instance for it that we add to some global vec.

@j-lanson j-lanson added type: enhancement New feature or request product: rust-sdk Relates to the Rust plugin SDK labels Sep 24, 2024
@j-lanson j-lanson self-assigned this Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: rust-sdk Relates to the Rust plugin SDK type: enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

1 participant