23 breaking releases
0.27.0 | Feb 9, 2023 |
---|---|
0.25.0 | Nov 9, 2022 |
0.16.0 | Jun 14, 2022 |
0.11.0 | Mar 28, 2022 |
0.3.0 | Dec 14, 2021 |
#29 in #ockam
835 downloads per month
Used in 24 crates
(15 directly)
53KB
1K
SLoC
ockam_macros
Ockam is a library for building devices that communicate securely, privately and trustfully with cloud services and other devices.
This crate provides shared macros.
Usage
Add this to your Cargo.toml
:
[dependencies]
ockam_macros = "0.27.0"
All macros except for those used exclusively for testing purposes are re-exported by the ockam
crate, so you may see examples where the macros are exported from ockam_macros
if are related to tests or from ockam
in any other case.
You can read more about how to use the macros and the supported attributes by each of them in the crate documentation.
AsyncTryClone
Implements the AsyncTryClone
trait as defined in ockam_core::AsyncTryClone
.
#[derive(ockam::AsyncTryClone)]
pub struct MyStruct {
a: u32,
}
Message
Implements the Message
trait as defined in ockam_core::Message
.
#[derive(ockam::Message, Deserialize, Serialize)]
pub struct MyStruct {
a: u32,
}
Node
Transforms the main
function into an async function that sets up a node and provides a Context
to interact with it.
#[ockam::node]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
// ...
}
If you are executing your code in a no_std
platform that doesn't support a main
entry point, you must use the no_main
attribute:
#[ockam::node(no_main)]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
// ...
}
Tests
To write node-related tests:
#[ockam::test]
async fn main(mut ctx: ockam::Context) -> ockam::Result<()> {
// ...
}
To write vault-related tests:
use ockam_vault::Vault;
fn new_vault() -> Vault {
Vault::default()
}
#[ockam_macros::vault_test]
fn hkdf() {}
Develop
Due to dependencies constraints, the tests for all the macros contained in this crate are located in the ockam
crate.
To test changes done in any of the macros you can use the macro_expand_playground
from the ockam
crate to see how a macro expands
a given input.
License
This code is licensed under the terms of the Apache License 2.0.
Dependencies
~0.7–1MB
~26K SLoC