Skip to content

Commit

Permalink
Use aws_smithy_types::primitive::Parse in the server
Browse files Browse the repository at this point in the history
This further reduces the number of request rejection variants.
https://docs.rs/aws-smithy-types/latest/aws_smithy_types/primitive/trait.Parse.html

Closes #1232.
  • Loading branch information
david-perez committed Apr 3, 2023
1 parent f708076 commit 433b377
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1124,17 +1124,13 @@ class ServerHttpBoundProtocolTraitImplGenerator(
check(target is NumberShape || target is BooleanShape)
rustTemplate(
"""
let value = std::str::FromStr::from_str(value)?;
let value = <_ as #{PrimitiveParse}>::parse_smithy_primitive(value)?;
""",
*codegenScope,
"PrimitiveParse" to RuntimeType.smithyTypes(runtimeConfig).resolve("primitive::Parse"),
)
}
}
rust(
"""
Ok(${symbolProvider.wrapOptional(binding.member, "value")})
""",
)
rust("Ok(${symbolProvider.wrapOptional(binding.member, "value")})")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,6 @@ pub enum RequestRejection {
/// into "primitive" types.
PrimitiveParse(crate::Error),

// The following three variants are used when failing to deserialize strings from a URL query
// string and URI path labels into "primitive" types.
// TODO(https://github.com/awslabs/smithy-rs/issues/1232): They should be removed and
// conflated into the `PrimitiveParse` variant above after this issue is resolved.
IntParse(crate::Error),
FloatParse(crate::Error),
BoolParse(crate::Error),

/// Used when consuming the input struct builder, and constraint violations occur.
// Unlike the rejections above, this does not take in `crate::Error`, since it is constructed
// directly in the code-generated SDK instead of in this crate.
Expand Down Expand Up @@ -192,9 +184,6 @@ convert_to_request_rejection!(aws_smithy_json::deserialize::error::DeserializeEr
convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse);
convert_to_request_rejection!(aws_smithy_types::date_time::DateTimeParseError, DateTimeParse);
convert_to_request_rejection!(aws_smithy_types::primitive::PrimitiveParseError, PrimitiveParse);
convert_to_request_rejection!(std::str::ParseBoolError, BoolParse);
convert_to_request_rejection!(std::num::ParseFloatError, FloatParse);
convert_to_request_rejection!(std::num::ParseIntError, IntParse);
convert_to_request_rejection!(serde_urlencoded::de::Error, InvalidUtf8);

impl From<nom::Err<nom::error::Error<&str>>> for RequestRejection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ pub enum RequestRejection {

PrimitiveParse(crate::Error),

IntParse(crate::Error),
FloatParse(crate::Error),
BoolParse(crate::Error),

ConstraintViolation(String),
}

Expand Down Expand Up @@ -81,9 +77,6 @@ convert_to_request_rejection!(aws_smithy_xml::decode::XmlDecodeError, XmlDeseria
convert_to_request_rejection!(aws_smithy_http::header::ParseError, HeaderParse);
convert_to_request_rejection!(aws_smithy_types::date_time::DateTimeParseError, DateTimeParse);
convert_to_request_rejection!(aws_smithy_types::primitive::PrimitiveParseError, PrimitiveParse);
convert_to_request_rejection!(std::str::ParseBoolError, BoolParse);
convert_to_request_rejection!(std::num::ParseFloatError, FloatParse);
convert_to_request_rejection!(std::num::ParseIntError, IntParse);
convert_to_request_rejection!(serde_urlencoded::de::Error, InvalidUtf8);

impl From<nom::Err<nom::error::Error<&str>>> for RequestRejection {
Expand Down

0 comments on commit 433b377

Please sign in to comment.