-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sylvia: Describe attribute forwarding (#124)
- Loading branch information
Showing
7 changed files
with
195 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
tags: ["sylvia", "attributes"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
|
||
# `sv::attr` attribute | ||
|
||
Use `sv::attr` to forward an external attribute to the generated message variant. | ||
|
||
## Macros | ||
|
||
List of macros supporting the `sv::attr` attribute: | ||
|
||
- [`contract`](../macros/contract) | ||
- [`interface`](../macros/interface) | ||
|
||
## Usage | ||
|
||
Use the `sv::attr` above any of the methods marked with | ||
[`#[sv::msg(exec|sudo|query)]`](../attributes/msg) attribute. | ||
|
||
```rust {19} | ||
use sylvia::contract; | ||
use sylvia::cw_std::{Response, StdResult}; | ||
use sylvia::types::{ExecCtx, InstantiateCtx}; | ||
|
||
pub struct MyContract; | ||
|
||
#[contract] | ||
impl Contract { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
|
||
#[sv::msg(exec)] | ||
#[sv::attr(serde(rename = "execute"))] | ||
fn exec(&self, ctx: ExecCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
} | ||
``` | ||
|
||
The [`contract`](../macros/contract) and [`interface`](../macros/interface) macros will decorate the | ||
message variant with the attribute provided in `sv::attr`. | ||
|
||
```rust {2} | ||
pub enum ExecMsg { | ||
#[serde(rename = "execute")] | ||
Exec {}, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
tags: ["sylvia", "attributes"] | ||
--- | ||
|
||
import { Callout } from "nextra/components"; | ||
|
||
# `sv::msg_attr` attribute | ||
|
||
Use `sv::msg_attr` to forward an external attribute to the generated message. | ||
|
||
## Macros | ||
|
||
List of macros supporting the `sv::msg_attr` attribute: | ||
|
||
- [`contract`](../macros/contract) | ||
- [`interface`](../macros/interface) | ||
|
||
## Usage | ||
|
||
Use the `sv::msg_attr` above any of the methods marked with [`#[sv::msg(..)]`](../attributes/msg) | ||
attribute. | ||
|
||
```rust {19} | ||
use sylvia::contract; | ||
use sylvia::cw_std::{Response, StdResult}; | ||
use sylvia::types::InstantiateCtx; | ||
|
||
pub struct MyContract; | ||
|
||
#[contract] | ||
#[sv::msg_attr(instantiate, derive(MyDeriveMacro))] | ||
#[sv::msg_attr(instantiate, MyAttributeMacro(param))] | ||
#[sv::msg_attr(instantiate, AttributeForMacro(param1, param2))] | ||
impl MyContract { | ||
pub fn new() -> Self { | ||
Self | ||
} | ||
|
||
#[sv::msg(instantiate)] | ||
fn instantiate(&self, ctx: InstantiateCtx) -> StdResult<Response> { | ||
Ok(Response::new()) | ||
} | ||
} | ||
``` | ||
|
||
The [`contract`](../macros/contract) and [`interface`](../macros/interface) macros will decorate the | ||
message with the attributes/macros provided in `sv::msg_attr`. | ||
|
||
```rust {8, 10-11} | ||
#[derive( | ||
sylvia::serde::Serialize, | ||
sylvia::serde::Deserialize, | ||
Clone, | ||
Debug, | ||
PartialEq, | ||
sylvia::schemars::JsonSchema, | ||
MyDeriveMacro, | ||
)] | ||
#[MyAttributeMacro(param)] | ||
#[AttributeForMacro(param1, param2)] | ||
#[serde(rename_all = "snake_case")] | ||
pub struct InstantiateMsg {} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters