iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

[WIP] API Gateway Data Model #39

Open naftulikay opened 6 years ago

naftulikay commented 6 years ago

Tests are broken until I can get a deserializer written which can deserialize Value::Null into Default::default() for T: Default.

mockersf commented 6 years ago

Based on https://github.com/serde-rs/serde/issues/1098#issuecomment-346706565, you can do this:

#[derive(Deserialize)]
struct Test {
    #[serde(default, deserialize_with = "nullable_default")]
    default_field: DefaultField,
}

#[derive(Deserialize, Default)]
struct DefaultField {
    u8: u8,
}
fn nullable_default<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
    D: Deserializer<'de>,
    T: Default + Deserialize<'de>,
{
    let opt = Option::deserialize(deserializer)?;
    Ok(opt.unwrap_or_else(T::default))
}

This will use default for type if the field is missing or null.

naftulikay commented 6 years ago

I apologize for my delay on this, new job, excuses, etc.

softprops commented 6 years ago

Is there anyone I can help move this forward? I'd love to help

srijs commented 5 years ago

I've recently spent some time doing this for rust-aws-lambda over here: https://github.com/srijs/rust-aws-lambda/tree/master/aws_lambda_gateway, which then led to cool things like being able to run tower-web apps on lambda.

If you're interested, I'd be happy to see if this can be generalized so that it's useful for crowbar as well. Between this and what's being discussed in #32, maybe we can find a way to have an ecosystem of crates that can be used from either runtime?