-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: more informative README and call* methods (#454)
* docs: ic-cdk README * docs: README for macros * docs: call* methods * chore: bump version and changelog * fix: grammar and format * fix: a leftover lock change from other PR
- Loading branch information
Showing
12 changed files
with
247 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,11 +1,32 @@ | ||
# ic-cdk-macros | ||
|
||
**Internet Computer Canister Development Kit** | ||
|
||
[](https://docs.rs/ic-cdk-macros/) | ||
[](https://crates.io/crates/ic-cdk-macros) | ||
[](https://github.com/dfinity/cdk-rs/blob/main/src/ic-cdk-macros/LICENSE) | ||
[](https://crates.io/crates/ic-cdk-macros) | ||
[](https://github.com/dfinity/cdk-rs/actions/workflows/ci.yml) | ||
|
||
This crate provides attribute macros, with which you can annotate regular rust functions to be public interfaces of a canister. | ||
# ic-cdk-macros | ||
|
||
This crate provides a set of macros to facilitate canister development. | ||
|
||
The macros fall into two categories: | ||
|
||
* To register functions as canister entry points | ||
* To export Candid definitions | ||
|
||
## Register functions as canister entry points | ||
|
||
These macros are directly related to the [Internet Computer Specification](https://internetcomputer.org/docs/current/references/ic-interface-spec#entry-points). | ||
|
||
* [`init`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.init.html) | ||
* [`pre_upgrade`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.pre_upgrade.html) | ||
* [`post_upgrade`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.post_upgrade.html) | ||
* [`inspect_message`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.inspect_message.html) | ||
* [`heartbeat`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.heartbeat.html) | ||
* [`update`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.update.html) | ||
* [`query`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.query.html) | ||
|
||
## Export Candid definitions | ||
|
||
* [`export_candid`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/macro.export_candid.html) | ||
|
||
Check [Generating Candid files for Rust canisters](https://internetcomputer.org/docs/current/developer-docs/backend/candid/generating-candid/) for more details. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,80 @@ | ||
# ic-cdk | ||
|
||
**Internet Computer Canister Development Kit** | ||
|
||
[](https://docs.rs/ic-cdk/) | ||
[](https://crates.io/crates/ic-cdk) | ||
[](https://github.com/dfinity/cdk-rs/blob/main/src/ic-cdk/LICENSE) | ||
[](https://crates.io/crates/ic-cdk) | ||
[](https://github.com/dfinity/cdk-rs/actions/workflows/ci.yml) | ||
|
||
# ic-cdk | ||
|
||
Canister Developer Kit for the Internet Computer. | ||
|
||
## Background | ||
|
||
On the Internet Computer, smart contracts come in the form of canisters which are WebAssembly modules. | ||
|
||
Canisters expose entry points which can be called both by other canisters and by parties external to the IC. | ||
|
||
This library aims to provide a Rust-ergonomic abstraction to implement Canister entry points. | ||
|
||
## Using `ic-cdk` | ||
|
||
In Cargo.toml: | ||
|
||
```toml | ||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
ic-cdk = "0.12" | ||
# Only necessary if you want to define Candid data types | ||
candid = "0.10" | ||
``` | ||
|
||
Then in Rust source code: | ||
|
||
```rust | ||
#[ic_cdk::query] | ||
fn hello() -> String { | ||
"world".to_string() | ||
} | ||
``` | ||
|
||
This will register a **query** entry point named `hello`. | ||
|
||
## Macros | ||
|
||
This library re-exports macros defined in `ic-cdk-macros` crate. | ||
|
||
The macros fall into two categories: | ||
|
||
* To register functions as canister entry points | ||
* To export Candid definitions | ||
|
||
### Register functions as canister entry points | ||
|
||
These macros are directly related to the [Internet Computer Specification](https://internetcomputer.org/docs/current/references/ic-interface-spec#entry-points). | ||
|
||
* [`init`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.init.html) | ||
* [`pre_upgrade`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.pre_upgrade.html) | ||
* [`post_upgrade`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.post_upgrade.html) | ||
* [`inspect_message`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.inspect_message.html) | ||
* [`heartbeat`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.heartbeat.html) | ||
* [`update`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.update.html) | ||
* [`query`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/attr.query.html) | ||
|
||
### Export Candid definitions | ||
|
||
* [`export_candid`](https://docs.rs/ic-cdk-macros/latest/ic_cdk_macros/macro.export_candid.html) | ||
|
||
Check [Generating Candid files for Rust canisters](https://internetcomputer.org/docs/current/developer-docs/backend/candid/generating-candid/) for more details. | ||
|
||
## More examples | ||
|
||
* [Basic examples](https://github.com/dfinity/cdk-rs/tree/main/examples): Demonstrate usage of `ic-cdk` API. | ||
* [Comprehensive examples](https://github.com/dfinity/examples/tree/master/rust): Illustrate how to build useful Rust canisters. | ||
|
||
## Manage Data Structure in Stable Memory | ||
|
||
Using the `ic_cdk::storage::{stable_save, stable_restore}` API is easy but it doesn't scale well. | ||
|
||
[`ic-stable-structures`](https://crates.io/crates/ic-stable-structures) is recommended when you are dealing with multiple data structures with larger datasets. |
Oops, something went wrong.