Skip to content

Commit

Permalink
[#15] QueryStringDeserializer trait 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Aug 26, 2024
1 parent 4c6409f commit f5ca56e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rupring/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ impl Request {
}
}

#[derive(Debug, Clone)]
pub struct QueryString(pub Vec<String>);

pub trait QueryStringDeserializer<T>: Sized {
type Error;

fn deserialize(&self) -> Result<T, Self::Error>;
}

#[derive(Debug, Clone)]
pub struct ParamString(pub String);

Expand Down
14 changes: 14 additions & 0 deletions rupring_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,20 @@ pub fn derive_rupring_doc(item: TokenStream) -> TokenStream {
.as_str();
}

for field_name in query_field_names {
request_bind_code += format!(
r#"{field_name}: rupring::ParamString(
request.query_parameters["{field_name}"].clone()
).
deserialize().
map_err(
|_|Err(rupring::anyhow::anyhow!("{field_name} is invalid"))
)?,
"#
)
.as_str();
}

request_bind_code += format!("}};").as_str();

request_bind_code += "Ok(bound)";
Expand Down

0 comments on commit f5ca56e

Please sign in to comment.