Skip to content

Commit 5bbe8e4

Browse files
committed
PR feedback on adder commentary
1 parent 1db8a29 commit 5bbe8e4

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

component-model/examples/tutorial/adder/src/bindings.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Generated by `wit-bindgen` 0.36.0. DO NOT EDIT!
1+
// Generated by `wit-bindgen` 0.41.0. DO NOT EDIT!
22
// Options used:
33
// * runtime_path: "wit_bindgen_rt"
44
#[rustfmt::skip]
55
#[allow(dead_code, clippy::all)]
66
pub mod exports {
77
pub mod docs {
88
pub mod adder {
9-
#[allow(dead_code, clippy::all)]
9+
#[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)]
1010
pub mod add {
1111
#[used]
1212
#[doc(hidden)]
@@ -25,9 +25,10 @@ pub mod exports {
2525
#[doc(hidden)]
2626
macro_rules! __export_docs_adder_add_0_1_0_cabi {
2727
($ty:ident with_types_in $($path_to_types:tt)*) => {
28-
const _ : () = { #[export_name = "docs:adder/[email protected]#add"]
29-
unsafe extern "C" fn export_add(arg0 : i32, arg1 : i32,) -> i32 {
30-
$($path_to_types)*:: _export_add_cabi::<$ty > (arg0, arg1) } };
28+
const _ : () = { #[unsafe (export_name =
29+
"docs:adder/[email protected]#add")] unsafe extern "C" fn export_add(arg0
30+
: i32, arg1 : i32,) -> i32 { unsafe { $($path_to_types)*::
31+
_export_add_cabi::<$ty > (arg0, arg1) } } };
3132
};
3233
}
3334
#[doc(hidden)]
@@ -38,6 +39,7 @@ pub mod exports {
3839
}
3940
#[rustfmt::skip]
4041
mod _rt {
42+
#![allow(dead_code, clippy::all)]
4143
#[cfg(target_arch = "wasm32")]
4244
pub fn run_ctors_once() {
4345
wit_bindgen_rt::run_ctors_once();
@@ -102,8 +104,8 @@ mod _rt {
102104
}
103105
}
104106
}
105-
/// Generates `#[no_mangle]` functions to export the specified type as the
106-
/// root implementation of all generated traits.
107+
/// Generates `#[unsafe(no_mangle)]` functions to export the specified type as
108+
/// the root implementation of all generated traits.
107109
///
108110
/// For more information see the documentation of `wit_bindgen::generate!`.
109111
///
@@ -133,14 +135,17 @@ macro_rules! __export_adder_impl {
133135
#[doc(inline)]
134136
pub(crate) use __export_adder_impl as export;
135137
#[cfg(target_arch = "wasm32")]
136-
#[link_section = "component-type:wit-bindgen:0.36.0:docs:[email protected]:adder:encoded world"]
138+
#[unsafe(
139+
link_section = "component-type:wit-bindgen:0.41.0:docs:[email protected]:adder:encoded world"
140+
)]
137141
#[doc(hidden)]
142+
#[allow(clippy::octal_escapes)]
138143
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 203] = *b"\
139144
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07P\x01A\x02\x01A\x02\x01\
140-
B\x02\x01@\x02\x01ay\x01by\0y\x04\0\x03add\x01\0\x04\0\x14docs:adder/[email protected]\x05\
145+
B\x02\x01@\x02\x01xy\x01yy\0y\x04\0\x03add\x01\0\x04\0\x14docs:adder/[email protected]\x05\
141146
\0\x04\0\x16docs:adder/[email protected]\x04\0\x0b\x0b\x01\0\x05adder\x03\0\0\0G\x09pr\
142-
oducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rust\x06\
143-
0.36.0";
147+
oducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.227.1\x10wit-bindgen-rust\x06\
148+
0.41.0";
144149
#[inline(never)]
145150
#[doc(hidden)]
146151
pub fn __link_custom_section_describing_imports() {

component-model/examples/tutorial/adder/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#[allow(warnings)]
22
mod bindings;
33

4-
// Separating out the interface puts it in a sub-module
4+
// The comments that follow the use declaration below correlate the rust module path with their
5+
// `world.wit` counterparts:
56
use bindings::exports::docs::adder::add::Guest;
7+
// <- items bundled with `export` keyword
8+
// <- package namespace
9+
// <- package field
10+
// <- interface name
611

712
struct Component;
813

component-model/src/language-support/rust.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ Now, let's build our component, being sure to optimize with a release build:
8989
cargo component build --release
9090
```
9191

92-
You can use `wasm-tools` to inspect the WIT package generated by `cargo-component`:
93-
94-
95-
You can use `wasm-tools component wit` to output the WIT package of the component:
92+
You can use `wasm-tools` to output the WIT package of the component:
9693

9794
```console
9895
wasm-tools component wit target/wasm32-wasip1/release/add.wasm
@@ -118,7 +115,7 @@ package docs:[email protected] {
118115
### Running a Component
119116

120117
To verify that our component works, lets run it from a Rust application that knows how to run a
121-
component targeting the [`docs:adder/adder`](#adding-the-wit-world) world.
118+
component targeting the [`adder` world](#adding-the-wit-world).
122119

123120
The application uses [`wasmtime`](https://github.com/bytecodealliance/wasmtime) crates to generate
124121
Rust bindings, bring in WASI worlds, and execute the component.

0 commit comments

Comments
 (0)