wasmcloud_actor_extras/lib.rs
1//! # wasmCloud Extras Actor Interface
2//!
3//! This crate provides wasmCloud actors with an interface to the extras capability provider.
4//! Every wasmCloud host runtime automatically comes with a built-in extras provider. However,
5//! actors using this provider will still need to be signed with the `wasmcloud:extras`
6//! capability contract ID.
7//!
8//! The following functions are supported on the extras `Host` interface:
9//!
10//! * [request_guid](generated::Host::request_guid)
11//! * [request_sequence](generated::Host::request_sequence)
12//! * [request_random](generated::Host::request_random)
13//!
14//! Example:
15//!
16//! ```rust
17//! extern crate wapc_guest as guest;
18//! use guest::prelude::*;
19//! use wasmcloud_actor_core as actor;
20//! use wasmcloud_actor_extras as extras;
21//! use wasmcloud_actor_http_server as http;
22//! use serde_json::json;
23//! use log::{error, info};
24//! use extras::{GeneratorResult, GeneratorRequest};
25//!
26//! #[actor::init]
27//! pub fn init() {
28//! http::Handlers::register_handle_request(generate_guid);
29//! }
30//!
31//! /// Generate a Guid and return it in a JSON envelope
32//! fn generate_guid(_req: http::Request) -> HandlerResult<http::Response> {
33//! let request = GeneratorRequest { guid: true, random: false, sequence: false, min: 0, max: 0 };
34//! let guid = extras::default().request_guid(request)?;
35//! let result = json!({"guid": guid });
36//! Ok(http::Response::json(&result, 200, "OK"))
37//! }
38//!
39//! ```
40
41mod generated;
42#[allow(unused_imports)]
43pub use generated::*;
44
45/// Constant that can be used by capability providers when handling messages from actors
46pub const OP_REQUEST_GUID: &str = "RequestGuid";
47/// Constant that can be used by capability providers when handling messages from actors
48pub const OP_REQUEST_RANDOM: &str = "RequestRandom";
49/// Constant that can be used by capability providers when handling messages from actors
50pub const OP_REQUEST_SEQUENCE: &str = "RequestSequence";