Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Levick <[email protected]>
  • Loading branch information
rylev committed Oct 5, 2023
1 parent a540c71 commit 4289564
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 116 deletions.
42 changes: 21 additions & 21 deletions sdk/rust/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<spin_http_types::Request> for http::Request<Option<bytes::Bytes>> {
type Error = anyhow::Error;

fn try_from(spin_req: spin_http_types::Request) -> Result<Self, Self::Error> {
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<spin_http_types::Method> for http::Method {
fn from(spin_method: spin_http_types::Method) -> Self {
match spin_method {
Expand All @@ -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,
Expand All @@ -103,27 +103,27 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
http::header::HeaderValue::from_str(v)?,
);
}

Ok(())
}

impl TryFrom<spin_http_types::Response> for http::Response<Option<bytes::Bytes>> {
type Error = anyhow::Error;

fn try_from(spin_res: spin_http_types::Response) -> Result<Self, Self::Error> {
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,
Expand All @@ -135,38 +135,38 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {
http::header::HeaderValue::from_str(&v)?,
);
}

Ok(())
}

impl TryFrom<http::Response<Option<bytes::Bytes>>> for spin_http_types::Response {
type Error = anyhow::Error;

fn try_from(
http_res: http::Response<Option<bytes::Bytes>>,
) -> Result<Self, Self::Error> {
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,
body,
})
}
}

fn outbound_headers(hm: &http::HeaderMap) -> anyhow::Result<Vec<(String, String)>> {
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)
}
}
Expand Down
9 changes: 5 additions & 4 deletions sdk/rust/src/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
11 changes: 3 additions & 8 deletions sdk/rust/src/sqlite.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 10 additions & 10 deletions tests/http/headers-env-routes-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions tests/http/simple-spin-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4289564

Please sign in to comment.