diff --git a/crates/fuzzing/src/oracles.rs b/crates/fuzzing/src/oracles.rs index 2ed29e6a33..b656dc2eac 100644 --- a/crates/fuzzing/src/oracles.rs +++ b/crates/fuzzing/src/oracles.rs @@ -785,7 +785,6 @@ pub fn set_fuel(store: &mut Store, fuel: u64) { /// arbitrary types and values. pub fn dynamic_component_api_target(input: &mut arbitrary::Unstructured) -> arbitrary::Result<()> { use crate::generators::component_types; - use anyhow::Result; use component_fuzz_util::{TestCase, EXPORT_FUNCTION, IMPORT_FUNCTION}; use component_test_util::FuncExt; use wasmtime::component::{Component, Linker, Val}; diff --git a/crates/wasmtime/src/component/mod.rs b/crates/wasmtime/src/component/mod.rs index f1f88c2d71..15212fb928 100644 --- a/crates/wasmtime/src/component/mod.rs +++ b/crates/wasmtime/src/component/mod.rs @@ -82,7 +82,6 @@ pub(crate) use self::store::ComponentStoreData; /// Then you can interact with the generated bindings like so: /// /// ```rust,ignore -/// use anyhow::Result; /// use wasmtime::component::*; /// use wasmtime::{Config, Engine, Store}; /// @@ -97,12 +96,12 @@ pub(crate) use self::store::ComponentStoreData; /// impl HelloWorldImports for MyState { /// // Note the `Result` return value here where `Ok` is returned back to /// // the component and `Err` will raise a trap. -/// fn name(&mut self) -> Result { +/// fn name(&mut self) -> wasmtime::Result { /// Ok(self.name.clone()) /// } /// } /// -/// fn main() -> Result<()> { +/// fn main() -> wasmtime::Result<()> { /// // Configure an `Engine` and compile the `Component` that is being run for /// // the application. /// let mut config = Config::new(); @@ -168,7 +167,6 @@ pub(crate) use self::store::ComponentStoreData; /// Then you can interact with the generated bindings like so: /// /// ```rust,ignore -/// use anyhow::Result; /// use wasmtime::component::*; /// use wasmtime::{Config, Engine, Store}; /// @@ -180,16 +178,16 @@ pub(crate) use self::store::ComponentStoreData; /// /// // Note that the trait here is per-interface and within a submodule now. /// impl host::Host for MyState { -/// fn gen_random_integer(&mut self) -> Result { +/// fn gen_random_integer(&mut self) -> wasmtime::Result { /// Ok(rand::thread_rng().gen()) /// } /// -/// fn sha256(&mut self, bytes: Vec) -> Result { +/// fn sha256(&mut self, bytes: Vec) -> wasmtime::Result { /// // ... /// } /// } /// -/// fn main() -> Result<()> { +/// fn main() -> wasmtime::Result<()> { /// let mut config = Config::new(); /// config.wasm_component_model(true); /// let engine = Engine::new(&config)?; diff --git a/crates/wasmtime/src/lib.rs b/crates/wasmtime/src/lib.rs index a11bdd9406..dd54cdc77e 100644 --- a/crates/wasmtime/src/lib.rs +++ b/crates/wasmtime/src/lib.rs @@ -27,10 +27,9 @@ //! An example of using Wasmtime looks like: //! //! ``` -//! use anyhow::Result; //! use wasmtime::*; //! -//! fn main() -> Result<()> { +//! fn main() -> wasmtime::Result<()> { //! // Modules can be compiled through either the text or binary format //! let engine = Engine::default(); //! let wat = r#" @@ -141,10 +140,9 @@ //! For example we can reimplement the above example with a `Linker`: //! //! ``` -//! use anyhow::Result; //! use wasmtime::*; //! -//! fn main() -> Result<()> { +//! fn main() -> wasmtime::Result<()> { //! let engine = Engine::default(); //! let wat = r#" //! (module @@ -301,11 +299,10 @@ //! An example of using WASI looks like: //! //! ```no_run -//! # use anyhow::Result; //! # use wasmtime::*; //! use wasmtime_wasi::sync::WasiCtxBuilder; //! -//! # fn main() -> Result<()> { +//! # fn main() -> wasmtime::Result<()> { //! // Compile our module and create a `Linker` which has WASI functions defined //! // within it. //! let engine = Engine::default(); @@ -333,7 +330,7 @@ //! use std::str; //! //! # use wasmtime::*; -//! # fn main() -> anyhow::Result<()> { +//! # fn main() -> wasmtime::Result<()> { //! let mut store = Store::default(); //! let log_str = Func::wrap(&mut store, |mut caller: Caller<'_, ()>, ptr: i32, len: i32| { //! // Use our `caller` context to learn about the memory export of the @@ -427,6 +424,13 @@ pub use crate::trap::*; pub use crate::types::*; pub use crate::values::*; +/// A convenience wrapper for `Result`. +/// +/// This type can be used to interact with `wasmtimes`'s extensive use +/// of `anyhow::Error` while still not directly depending on `anyhow`. +/// This type alias is identical to `anyhow::Result`. +pub use anyhow::{Error, Result}; + #[cfg(feature = "component-model")] pub mod component; diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index 9fdde53177..21f0296131 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -179,7 +179,7 @@ impl Wasmtime { " pub fn new( __exports: &mut wasmtime::component::ExportInstance<'_, '_>, - ) -> anyhow::Result<{camel}> {{ + ) -> wasmtime::Result<{camel}> {{ " ); let mut fields = Vec::new(); @@ -267,7 +267,7 @@ impl Wasmtime { mut store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker, - ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {{ + ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {{ let instance = linker.instantiate{async__}(&mut store, component){await_}?; Ok((Self::new(store, &instance)?, instance)) }} @@ -278,7 +278,7 @@ impl Wasmtime { pub {async_} fn instantiate_pre( mut store: impl wasmtime::AsContextMut, instance_pre: &wasmtime::component::InstancePre, - ) -> anyhow::Result<(Self, wasmtime::component::Instance)> {{ + ) -> wasmtime::Result<(Self, wasmtime::component::Instance)> {{ let instance = instance_pre.instantiate{async__}(&mut store){await_}?; Ok((Self::new(store, &instance)?, instance)) }} @@ -294,7 +294,7 @@ impl Wasmtime { pub fn new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, - ) -> anyhow::Result {{ + ) -> wasmtime::Result {{ let mut store = store.as_context_mut(); let mut exports = instance.exports(&mut store); let mut __exports = exports.root(); @@ -397,7 +397,7 @@ impl Wasmtime { pub fn add_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, - ) -> anyhow::Result<()> + ) -> wasmtime::Result<()> where U: \ " ); @@ -442,7 +442,7 @@ impl Wasmtime { pub fn add_root_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, - ) -> anyhow::Result<()> + ) -> wasmtime::Result<()> where U: {world_trait}{maybe_send} {{ let mut linker = linker.root(); @@ -978,7 +978,7 @@ impl<'a> InterfaceGenerator<'a> { pub fn add_to_linker( linker: &mut wasmtime::component::Linker, get: impl Fn(&mut T) -> &mut U + Send + Sync + Copy + 'static, - ) -> anyhow::Result<()> + ) -> wasmtime::Result<()> where {where_clause}, {{ " @@ -1124,9 +1124,9 @@ impl<'a> InterfaceGenerator<'a> { self.push_str(&error_typename); self.push_str(">"); } else { - // All other functions get their return values wrapped in an anyhow::Result. + // All other functions get their return values wrapped in an wasmtime::Result. // Returning the anyhow::Error case can be used to trap. - self.push_str("anyhow::Result<"); + self.push_str("wasmtime::Result<"); self.print_result_ty(&func.results, TypeMode::Owned); self.push_str(">"); } @@ -1174,7 +1174,7 @@ impl<'a> InterfaceGenerator<'a> { self.print_ty(¶m.1, TypeMode::AllBorrowed("'_")); self.push_str(","); } - self.src.push_str(") -> anyhow::Result<"); + self.src.push_str(") -> wasmtime::Result<"); self.print_result_ty(&func.results, TypeMode::Owned); if self.gen.opts.async_ { diff --git a/tests/all/memory_creator.rs b/tests/all/memory_creator.rs index cdf4c5c9e9..01cc0fabfb 100644 --- a/tests/all/memory_creator.rs +++ b/tests/all/memory_creator.rs @@ -57,7 +57,7 @@ mod not_for_windows { Some(self.size - self.guard_size) } - fn grow_to(&mut self, new_size: usize) -> Result<(), anyhow::Error> { + fn grow_to(&mut self, new_size: usize) -> wasmtime::Result<()> { println!("grow to {:x}", new_size); let delta = new_size - self.used_wasm_bytes; unsafe {