Skip to content

Commit 14629cc

Browse files
authored
[wasm-metadata] add example to README (#2057)
1 parent 7dbb11d commit 14629cc

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

  • crates/wasm-metadata/src

crates/wasm-metadata/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
11
//! Read and manipulate WebAssembly metadata
2+
//!
3+
//! # Examples
4+
//!
5+
//! **Read metadata from a Wasm binary**
6+
//!
7+
//! ```no_run
8+
//! # #![allow(unused)]
9+
//! # fn main() -> Result<(), anyhow::Error> {
10+
//! use wasm_metadata::Payload;
11+
//! use std::fs;
12+
//!
13+
//! let wasm = fs::read("program.wasm")?;
14+
//! let metadata = Payload::from_binary(&wasm)?.metadata();
15+
//! # Ok(()) }
16+
//! ```
17+
//!
18+
//! **Add metadata to a Wasm binary**
19+
//!
20+
//! ```no_run
21+
//! # #![allow(unused)]
22+
//! # fn main() -> Result<(), anyhow::Error> {
23+
//! use wasm_metadata::*;
24+
//! use std::fs;
25+
//!
26+
//! let wasm = fs::read("program.wasm")?;
27+
//!
28+
//! let metadata = AddMetadata {
29+
//! name: Some("program".to_owned()),
30+
//! language: vec![("tunalang".to_owned(), "1.0.0".to_owned())],
31+
//! processed_by: vec![("chashu-tools".to_owned(), "1.0.1".to_owned())],
32+
//! sdk: vec![],
33+
//! authors: Some(Authors::new("Chashu Cat")),
34+
//! description: Some(Description::new("Chashu likes tuna")),
35+
//! licenses: Some(Licenses::new("Apache-2.0 WITH LLVM-exception")?),
36+
//! source: Some(Source::new("https://github.com/chashu/chashu-tools")?),
37+
//! homepage: Some(Homepage::new("https://github.com/chashu/chashu-tools")?),
38+
//! revision: Some(Revision::new("de978e17a80c1118f606fce919ba9b7d5a04a5ad")),
39+
//! version: Some(Version::new("1.0.0")),
40+
//! };
41+
//!
42+
//! let wasm = metadata.to_wasm(&wasm)?;
43+
//! fs::write("program.wasm", &wasm)?;
44+
//! # Ok(()) }
45+
//! ```
246
347
#![warn(missing_debug_implementations, missing_docs)]
448

0 commit comments

Comments
 (0)