#[create_wit_file]
Expand description
Annotates a module with #[golem_rust_macro::create_wit_file]
and generates WIT file in the root of your project.
Supports enums, structs, traits and alias types.
§Example:
#[golem_rust_macro::create_wit_file("auction_app.wit")]
mod auction_app {
struct BidderId {
bidder_id: String,
}
struct AuctionId {
auction_id: String,
}
struct Auction {
auction_id: Option<AuctionId>,
name: String,
description: String,
starting_price: f32,
deadline: Deadline,
}
enum BidResult {
Failure(String),
Success,
}
type Deadline = u64;
trait AuctionService {
fn initialize(auction: Auction);
fn bid(bidder_id: BidderId, price: f32) -> BidResult;
fn close_auction() -> Option<BidderId>;
fn create_bidder(name: String, address: String) -> BidderId;
fn create_auction(
name: String,
description: String,
starting_price: f32,
deadline: u64,
) -> AuctionId;
fn get_auctions() -> Vec<Auction>;
}
}
File auction_app.wit
is then created with the following content.
ⓘ
package auction:app
interface api {
record bidder-id {
bidder-id: string,
}
record auction-id {
auction-id: string,
}
record auction {
auction-id: option<auction-id>,
name: string,
description: string,
starting-price: float32,
deadline: deadline,
}
variant bid-result {
failure(string),
success
}
type deadline = u64
initialize: func(auction: auction)
bid: func(bidder-id: bidder-id, price: float32) -> bid-result
close-auction: func() -> option<bidder-id>
create-bidder: func(name: string, address: string) -> bidder-id
create-auction: func(name: string, description: string, starting-price: float32, deadline: u64) -> auction-id
get-auctions: func() -> list<auction>
}
world golem-service {
export api
}