@@ -8,6 +8,44 @@ use std::sync::Arc;
88use tracing:: debug;
99use wasmtime:: component:: { HasData , Resource , ResourceTable } ;
1010
11+ /// A helper struct which implements [`HasData`] for the `wasi:filesystem` APIs.
12+ ///
13+ /// This can be useful when directly calling `add_to_linker` functions directly,
14+ /// such as [`wasmtime_wasi::p2::bindings::filesystem::types::add_to_linker`] as
15+ /// the `D` type parameter. See [`HasData`] for more information about the type
16+ /// parameter's purpose.
17+ ///
18+ /// When using this type you can skip the [`WasiFilesystemView`] trait, for
19+ /// example.
20+ ///
21+ /// # Examples
22+ ///
23+ /// ```
24+ /// use wasmtime::component::{Linker, ResourceTable};
25+ /// use wasmtime::{Engine, Result, Config};
26+ /// use wasmtime_wasi::filesystem::*;
27+ ///
28+ /// struct MyStoreState {
29+ /// table: ResourceTable,
30+ /// filesystem: WasiFilesystemCtx,
31+ /// }
32+ ///
33+ /// fn main() -> Result<()> {
34+ /// let mut config = Config::new();
35+ /// config.async_support(true);
36+ /// let engine = Engine::new(&config)?;
37+ /// let mut linker = Linker::new(&engine);
38+ ///
39+ /// wasmtime_wasi::p2::bindings::filesystem::types::add_to_linker::<MyStoreState, WasiFilesystem>(
40+ /// &mut linker,
41+ /// |state| WasiFilesystemCtxView {
42+ /// table: &mut state.table,
43+ /// ctx: &mut state.filesystem,
44+ /// },
45+ /// )?;
46+ /// Ok(())
47+ /// }
48+ /// ```
1149pub struct WasiFilesystem ;
1250
1351impl HasData for WasiFilesystem {
@@ -16,8 +54,8 @@ impl HasData for WasiFilesystem {
1654
1755#[ derive( Clone , Default ) ]
1856pub struct WasiFilesystemCtx {
19- pub allow_blocking_current_thread : bool ,
20- pub preopens : Vec < ( Dir , String ) > ,
57+ pub ( crate ) allow_blocking_current_thread : bool ,
58+ pub ( crate ) preopens : Vec < ( Dir , String ) > ,
2159}
2260
2361pub struct WasiFilesystemCtxView < ' a > {
0 commit comments