| Crates.io | wasmcloud-interface-factorial |
| lib.rs | wasmcloud-interface-factorial |
| version | 0.10.0 |
| created_at | 2021-08-30 01:08:03.242615+00 |
| updated_at | 2023-09-19 21:40:02.688049+00 |
| description | Interface library for the wasmcloud factorial capability, wasmcloud:example:factorial |
| homepage | https://wasmcloud.dev |
| repository | https://github.com/wasmcloud/interfaces |
| max_upload_size | |
| id | 443956 |
| size | 9,262 |
This is the definition for the interface used for examples and illustrations with the contract ID of wasmcloud:example:factorial.
This is an interface for a simple service that calculates the factorial of a whole number.
NOTE that this is just an example, and we would not recommend a real-world production scenario where you use an interface and accompanying capability provider for factorial calculations.
The following is a list of implementations of the wasmcloud:example:factorial contract. Feel free to submit a PR adding your implementation if you have a community/open source version.
| Name | Vendor | Description |
|---|---|---|
| Factorial | wasmCloud | wasmCloud example implementation of the Factorial interface |
Calculate a factorial, handling the error case
use wasmbus_rpc::actor::prelude::Context;
use wasmcloud_interface_factorial::{Factorial, FactorialSender};
async fn factorial(ctx: &Context, n: u32) -> u64 {
let factorial = FactorialSender::new();
match factorial.calculate(ctx, &n).await {
Ok(num) => num,
// 0 is not a possible factorial so it's obvious that an error occurred
Err(_e) => 0,
}
}