diff --git a/sdk/rust/macro/src/lib.rs b/sdk/rust/macro/src/lib.rs index 8461ba4b5..29634db44 100644 --- a/sdk/rust/macro/src/lib.rs +++ b/sdk/rust/macro/src/lib.rs @@ -56,28 +56,28 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { mod inbound_http_helpers { use super::fermyon::spin::http_types as spin_http_types; - + impl TryFrom for http::Request> { type Error = anyhow::Error; - + fn try_from(spin_req: spin_http_types::Request) -> Result { let mut http_req = http::Request::builder() .method(spin_req.method.clone()) .uri(&spin_req.uri); - + append_request_headers(&mut http_req, &spin_req)?; - + let body = match spin_req.body { Some(b) => b.to_vec(), None => Vec::new(), }; - + let body = Some(bytes::Bytes::from(body)); - + Ok(http_req.body(body)?) } } - + impl From for http::Method { fn from(spin_method: spin_http_types::Method) -> Self { match spin_method { @@ -91,7 +91,7 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { } } } - + fn append_request_headers( http_req: &mut http::request::Builder, spin_req: &spin_http_types::Request, @@ -103,27 +103,27 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { http::header::HeaderValue::from_str(v)?, ); } - + Ok(()) } - + impl TryFrom for http::Response> { type Error = anyhow::Error; - + fn try_from(spin_res: spin_http_types::Response) -> Result { let mut http_res = http::Response::builder().status(spin_res.status); append_response_headers(&mut http_res, spin_res.clone())?; - + let body = match spin_res.body { Some(b) => b.to_vec(), None => Vec::new(), }; let body = Some(bytes::Bytes::from(body)); - + Ok(http_res.body(body)?) } } - + fn append_response_headers( http_res: &mut http::response::Builder, spin_res: spin_http_types::Response, @@ -135,20 +135,20 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { http::header::HeaderValue::from_str(&v)?, ); } - + Ok(()) } - + impl TryFrom>> for spin_http_types::Response { type Error = anyhow::Error; - + fn try_from( http_res: http::Response>, ) -> Result { let status = http_res.status().as_u16(); let headers = Some(outbound_headers(http_res.headers())?); let body = http_res.body().as_ref().map(|b| b.to_vec()); - + Ok(spin_http_types::Response { status, headers, @@ -156,17 +156,17 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream { }) } } - + fn outbound_headers(hm: &http::HeaderMap) -> anyhow::Result> { let mut res = Vec::new(); - + for (k, v) in hm { res.push(( k.as_str().to_string(), std::str::from_utf8(v.as_bytes())?.to_string(), )); } - + Ok(res) } } diff --git a/sdk/rust/src/key_value.rs b/sdk/rust/src/key_value.rs index dc8966f1f..623feee42 100644 --- a/sdk/rust/src/key_value.rs +++ b/sdk/rust/src/key_value.rs @@ -9,12 +9,13 @@ use super::wit::fermyon::spin::key_value; #[cfg(feature = "json")] use serde::{de::DeserializeOwned, Serialize}; -/// Errors which may be raised by the methods of `Store` -pub use key_value::Error; - -/// A store +/// An open key-value store +// TODO: use `#[doc(inline)]` as soon as wit-bindgen#688 is merged pub use key_value::Store; +#[doc(inline)] +pub use key_value::Error; + impl Store { #[cfg(feature = "json")] /// Serialize the given data to JSON, then set it as the value for the specified `key`. diff --git a/sdk/rust/src/sqlite.rs b/sdk/rust/src/sqlite.rs index 4e9e3b109..f466e3101 100644 --- a/sdk/rust/src/sqlite.rs +++ b/sdk/rust/src/sqlite.rs @@ -1,15 +1,10 @@ use super::wit::fermyon::spin::sqlite; /// Represents a store in which key value tuples may be placed +// TODO: use `#[doc(inline)]` as soon as wit-bindgen#688 is merged pub use sqlite::Connection; -/// Errors which may be raised by the methods of `Store` -pub use sqlite::Error; -/// The result of making a query -pub use sqlite::QueryResult; -/// A row in a QueryResult -pub use sqlite::RowResult; -/// A single column's result from a database query -pub use sqlite::Value; +#[doc(inline)] +pub use sqlite::{Error, QueryResult, RowResult, Value}; impl sqlite::Connection { /// Open a connection to the default database diff --git a/tests/http/headers-env-routes-test/Cargo.lock b/tests/http/headers-env-routes-test/Cargo.lock index 59aad0e82..3ff927856 100644 --- a/tests/http/headers-env-routes-test/Cargo.lock +++ b/tests/http/headers-env-routes-test/Cargo.lock @@ -413,18 +413,18 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasm-encoder" -version = "0.33.1" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39de0723a53d3c8f54bed106cfbc0d06b3e4d945c5c5022115a61e3b29183ae" +checksum = "34180c89672b3e4825c3a8db4b61a674f1447afd5fe2445b2d22c3d8b6ea086c" dependencies = [ "leb128", ] [[package]] name = "wasm-metadata" -version = "0.10.5" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fab01638cbecc57afec7b53ce0e28620b44d7ae1dea53120c96dd08486c07ce" +checksum = "4f2c051ef041d348324b01ff0419f6f6593f094b4897d93c9cf52d5d1ac879ba" dependencies = [ "anyhow", "indexmap", @@ -437,9 +437,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.113.1" +version = "0.113.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a128cea7b8516703ab41b10a0b1aa9ba18d0454cd3792341489947ddeee268db" +checksum = "286049849b5a5bd09a8773171be96824afabffc7cc3df6caaf33a38db6cd07ae" dependencies = [ "indexmap", "semver", @@ -507,9 +507,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af872ef43ecb73cc49c7bd2dd19ef9117168e183c78cf70000dca0e14b6a5473" +checksum = "2e2bf941487fc5afa9e3fc94761f6b80ecef5a2bed6239b959d23d9de69e3448" dependencies = [ "anyhow", "bitflags 2.4.0", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.11.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dcd022610436a1873e60bfdd9b407763f2404adf7d1cb57912c7ae4059e57a5" +checksum = "a39edca9abb16309def3843af73b58d47d243fe33a9ceee572446bcc57556b9a" dependencies = [ "anyhow", "id-arena", diff --git a/tests/http/simple-spin-rust/Cargo.lock b/tests/http/simple-spin-rust/Cargo.lock index 2c79f9c47..c10b75288 100644 --- a/tests/http/simple-spin-rust/Cargo.lock +++ b/tests/http/simple-spin-rust/Cargo.lock @@ -421,18 +421,18 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasm-encoder" -version = "0.33.1" +version = "0.33.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39de0723a53d3c8f54bed106cfbc0d06b3e4d945c5c5022115a61e3b29183ae" +checksum = "34180c89672b3e4825c3a8db4b61a674f1447afd5fe2445b2d22c3d8b6ea086c" dependencies = [ "leb128", ] [[package]] name = "wasm-metadata" -version = "0.10.5" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fab01638cbecc57afec7b53ce0e28620b44d7ae1dea53120c96dd08486c07ce" +checksum = "4f2c051ef041d348324b01ff0419f6f6593f094b4897d93c9cf52d5d1ac879ba" dependencies = [ "anyhow", "indexmap", @@ -445,9 +445,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.113.1" +version = "0.113.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a128cea7b8516703ab41b10a0b1aa9ba18d0454cd3792341489947ddeee268db" +checksum = "286049849b5a5bd09a8773171be96824afabffc7cc3df6caaf33a38db6cd07ae" dependencies = [ "indexmap", "semver", @@ -515,9 +515,9 @@ dependencies = [ [[package]] name = "wit-component" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af872ef43ecb73cc49c7bd2dd19ef9117168e183c78cf70000dca0e14b6a5473" +checksum = "2e2bf941487fc5afa9e3fc94761f6b80ecef5a2bed6239b959d23d9de69e3448" dependencies = [ "anyhow", "bitflags 2.4.0", @@ -533,9 +533,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.11.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dcd022610436a1873e60bfdd9b407763f2404adf7d1cb57912c7ae4059e57a5" +checksum = "a39edca9abb16309def3843af73b58d47d243fe33a9ceee572446bcc57556b9a" dependencies = [ "anyhow", "id-arena", diff --git a/wit/preview2/key-value.wit b/wit/preview2/key-value.wit index 05a5eed36..6ff177063 100644 --- a/wit/preview2/key-value.wit +++ b/wit/preview2/key-value.wit @@ -1,75 +1,75 @@ interface key-value { - // An open key-value store + /// An open key-value store resource store { - // Open the store with the specified name. - // - // If `name` is "default", the default store is opened. Otherwise, - // `name` must refer to a store defined and configured in a runtime - // configuration file supplied with the application. - // - // `error::no-such-store` will be raised if the `name` is not recognized. + /// Open the store with the specified name. + /// + /// If `name` is "default", the default store is opened. Otherwise, + /// `name` must refer to a store defined and configured in a runtime + /// configuration file supplied with the application. + /// + /// `error::no-such-store` will be raised if the `name` is not recognized. open: static func(name: string) -> result - // Get the value associated with the specified `key` from the specified - // `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store, and `error::no-such-key` will be raised if there is no - // tuple for `key` in `store`. + /// Get the value associated with the specified `key` from the specified + /// `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store, and `error::no-such-key` will be raised if there is no + /// tuple for `key` in `store`. get: func(key: string) -> result, error> - // Set the `value` associated with the specified `key` in the specified - // `store`, overwriting any existing value. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. + /// Set the `value` associated with the specified `key` in the specified + /// `store`, overwriting any existing value. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. set: func(key: string, value: list) -> result<_, error> - // Delete the tuple with the specified `key` from the specified `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. No error is raised if a tuple did not previously - // exist for `key`. + /// Delete the tuple with the specified `key` from the specified `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. No error is raised if a tuple did not previously + /// exist for `key`. delete: func(key: string) -> result<_, error> - // Return whether a tuple exists for the specified `key` in the specified - // `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. + /// Return whether a tuple exists for the specified `key` in the specified + /// `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. exists: func(key: string) -> result - // Return a list of all the keys in the specified `store`. - // - // `error::invalid-store` will be raised if `store` is not a valid handle - // to an open store. + /// Return a list of all the keys in the specified `store`. + /// + /// `error::invalid-store` will be raised if `store` is not a valid handle + /// to an open store. get-keys: func() -> result, error> } - // The set of errors which may be raised by functions in this interface + /// The set of errors which may be raised by functions in this interface variant error { - // Too many stores have been opened simultaneously. Closing one or more - // stores prior to retrying may address this. + /// Too many stores have been opened simultaneously. Closing one or more + /// stores prior to retrying may address this. store-table-full, - // The host does not recognize the store name requested. Defining and - // configuring a store with that name in a runtime configuration file - // may address this. + /// The host does not recognize the store name requested. Defining and + /// configuring a store with that name in a runtime configuration file + /// may address this. no-such-store, - // The requesting component does not have access to the specified store - // (which may or may not exist). + /// The requesting component does not have access to the specified store + /// (which may or may not exist). access-denied, - // The store handle provided is not recognized, i.e. it was either never - // opened or has been closed. + /// The store handle provided is not recognized, i.e. it was either never + /// opened or has been closed. invalid-store, - // No key-value tuple exists for the specified key in the specified - // store. + /// No key-value tuple exists for the specified key in the specified + /// store. no-such-key, - // Some implementation-specific error has occurred (e.g. I/O) + /// Some implementation-specific error has occurred (e.g. I/O) io(string) } } diff --git a/wit/preview2/sqlite.wit b/wit/preview2/sqlite.wit index 35395f883..5d7badcb9 100644 --- a/wit/preview2/sqlite.wit +++ b/wit/preview2/sqlite.wit @@ -1,44 +1,45 @@ interface sqlite { - // A handle to an open sqlite instance + /// A handle to an open sqlite instance resource connection { - // Open a connection to a named database instance. - // - // If `database` is "default", the default instance is opened. - // - // `error::no-such-database` will be raised if the `name` is not recognized. + /// Open a connection to a named database instance. + /// + /// If `database` is "default", the default instance is opened. + /// + /// `error::no-such-database` will be raised if the `name` is not recognized. open: static func(database: string) -> result - // Execute a statement returning back data if there is any + /// Execute a statement returning back data if there is any execute: func(statement: string, parameters: list) -> result } - // The set of errors which may be raised by functions in this interface + /// The set of errors which may be raised by functions in this interface variant error { - // The host does not recognize the database name requested. + /// The host does not recognize the database name requested. no-such-database, - // The requesting component does not have access to the specified database (which may or may not exist). + /// The requesting component does not have access to the specified database (which may or may not exist). access-denied, - // The provided connection is not valid + /// The provided connection is not valid invalid-connection, - // The database has reached its capacity + /// The database has reached its capacity database-full, - // Some implementation-specific error has occurred (e.g. I/O) + /// Some implementation-specific error has occurred (e.g. I/O) io(string) } - // A result of a query + /// A result of a query record query-result { - // The names of the columns retrieved in the query + /// The names of the columns retrieved in the query columns: list, - // the row results each containing the values for all the columns for a given row + /// the row results each containing the values for all the columns for a given row rows: list, } - // A set of values for each of the columns in a query-result + /// A set of values for each of the columns in a query-result record row-result { values: list } + /// A single column's result from a database query variant value { integer(s64), real(float64),