Skip to content

Standard answers for common use cases #10

@toml01

Description

@toml01

Example:
A very common way to answer a handle message is simply { "status": "success" } or { "status": "failure" }.
Every time we do that we have to write something along the lines of:

Ok(HandleResponse {
        messages,
        log: vec![],
        data: Some(to_binary(&HandleAnswer::Send { status: Success })?),
    })

For this we of course have to declare:

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum ResponseStatus {
    Success,
    Failure,
}

#[derive(Serialize, Deserialize, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub enum HandleAnswer {
    Send {
        status: ResponseStatus,
    },
    ...
}

This is a lot of code and it's kind of annoying.
We should provide a standard implementation for common use cases that coders can use as a one-liner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions