Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more naming hygiene for Result #502

Merged
merged 4 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
impl<C> Client<C>
where C: #{aws_hyper}::SmithyConnector,
""",
"aws_hyper" to hyperDep.asType()
) {
"aws_hyper" to hyperDep.asType()
) {
operations.forEach { operation ->
val name = symbolProvider.toSymbol(operation).name
rust(
Expand Down Expand Up @@ -168,7 +168,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
Self { handle, inner: Default::default() }
}

pub async fn send(self) -> Result<#{ok}, #{sdk_err}<#{operation_err}>>
pub async fn send(self) -> std::result::Result<#{ok}, #{sdk_err}<#{operation_err}>>
where C: #{aws_hyper}::SmithyConnector,
{
let input = self.inner.build().map_err(|err|#{sdk_err}::ConstructionFailure(err.into()))?;
Expand Down
21 changes: 20 additions & 1 deletion codegen-test/model/naming-obstacle-course.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ service Config {
operations: [
ReservedWordsAsMembers,
StructureNamePunning,
ErrCollisions
ErrCollisions,
Result,
Option,
]
}

Expand Down Expand Up @@ -72,6 +74,13 @@ structure Vec {
pv_member: Boolean
}

structure Some {
pv_member: Boolean
}

structure None {
}


operation ErrCollisions {
errors: [
Expand All @@ -81,6 +90,16 @@ operation ErrCollisions {
]
}

operation Result {
input: Vec,
output: Some
}

operation Option {
input: Vec,
output: None
}

@error("client")
structure CollidingError {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BuilderGenerator(
val fallibleBuilder = StructureGenerator.fallibleBuilder(shape, symbolProvider)
val outputSymbol = symbolProvider.toSymbol(shape)
val returnType = when (fallibleBuilder) {
true -> "Result<${implBlockWriter.format(outputSymbol)}, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"
true -> "std::result::Result<${implBlockWriter.format(outputSymbol)}, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"
false -> implBlockWriter.format(outputSymbol)
}
implBlockWriter.docs("Consumes the builder and constructs a #D", outputSymbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
}

/// An ergonomic service client for `$humanName`.
///
///
/// This client allows ergonomic access to a `$humanName`-shaped service.
/// Each method corresponds to an endpoint defined in the service's Smithy model,
/// and the request and response shapes are auto-generated from that same model.
///
///
/// ## Constructing a Client
///
/// To construct a client, you need a few different things:
Expand Down Expand Up @@ -130,7 +130,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
/// `build` to construct the finalized output type. The
/// [`#{client}::Client`] builder is re-exported in this crate as
/// [`Builder`] for convenience.
///
///
/// In _most_ circumstances, you will want to use the following pattern
/// to construct a client:
///
Expand Down Expand Up @@ -163,7 +163,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
/// use tower::layer::util::Stack;
/// use tower::ServiceBuilder;
///
/// type AwsMiddlewareStack =
/// type AwsMiddlewareStack =
/// Stack<MapRequestLayer<SigV4SigningStage>,
/// Stack<MapRequestLayer<UserAgentStage>,
/// MapRequestLayer<AwsEndpointStage>>>,
Expand All @@ -190,7 +190,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
/// }
/// }
/// ```
///
///
/// ## Using a Client
///
/// Once you have a client set up, you can access the service's endpoints
Expand All @@ -199,7 +199,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
/// the various fields of the request. Once your request is complete, use
/// the `send` method to send the request. `send` returns a future, which
/// you then have to `.await` to get the service's response.
///
///
/// [builder pattern]: https://rust-lang.github.io/api-guidelines/type-safety.html##c-builder
/// [SigV4-signed requests]: https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
##[derive(Clone, std::fmt::Debug)]
Expand Down Expand Up @@ -286,7 +286,7 @@ class FluentClientGenerator(protocolConfig: ProtocolConfig) {
Self { handle, inner: Default::default() }
}

pub async fn send(self) -> Result<#{ok}, #{sdk_err}<#{operation_err}>> where
pub async fn send(self) -> std::result::Result<#{ok}, #{sdk_err}<#{operation_err}>> where
R::Policy: #{client}::bounds::SmithyRetryPolicy<#{input}OperationOutputAlias, #{ok}, #{operation_err}, #{input}OperationRetryAlias>,
{
let input = self.inner.build().map_err(|err|#{sdk_err}::ConstructionFailure(err.into()))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ abstract class HttpProtocolGenerator(
protected fun httpBuilderFun(implBlockWriter: RustWriter, f: RustWriter.() -> Unit) {
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(implBlockWriter)
implBlockWriter.rustBlock(
"fn request_builder_base(&self) -> Result<#T, #T>",
"fn request_builder_base(&self) -> std::result::Result<#T, #T>",
RuntimeType.HttpRequestBuilder, buildErrorT
) {
f(this)
Expand Down Expand Up @@ -180,7 +180,7 @@ abstract class HttpProtocolGenerator(
val sdkBody = RuntimeType.sdkBody(runtimeConfig)

val baseReturnType = buildOperationType(implBlockWriter, shape, features)
val returnType = "Result<$baseReturnType, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"
val returnType = "std::result::Result<$baseReturnType, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"

implBlockWriter.docs("Consumes the builder and constructs an Operation<#D>", outputSymbol)
// For codegen simplicity, allow `let x = ...; x`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RequestBindingGenerator(
val hasQuery = uriQuery(implBlockWriter)
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(implBlockWriter)
implBlockWriter.rustBlock(
"fn update_http_builder(&self, builder: #1T) -> Result<#1T, #2T>",
"fn update_http_builder(&self, builder: #1T) -> std::result::Result<#1T, #2T>",
RuntimeType.HttpRequestBuilder,
buildError
) {
Expand Down Expand Up @@ -129,7 +129,7 @@ class RequestBindingGenerator(
return false
}
writer.rustBlock(
"fn add_headers(&self, mut builder: #1T) -> Result<#1T, #2T>",
"fn add_headers(&self, mut builder: #1T) -> std::result::Result<#1T, #2T>",
RuntimeType.HttpRequestBuilder,
buildErrorT
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ResponseBindingGenerator(protocolConfig: ProtocolConfig, private val opera
val fnName = "deser_header_${fnName(operationShape, binding)}"
return RuntimeType.forInlineFun(fnName, "http_serde") { writer ->
writer.rustBlock(
"pub fn $fnName(header_map: &#T::HeaderMap) -> Result<#T, #T::ParseError>",
"pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>",
RuntimeType.http,
outputT,
headerUtil
Expand All @@ -90,7 +90,7 @@ class ResponseBindingGenerator(protocolConfig: ProtocolConfig, private val opera
val fnName = "deser_prefix_header_${fnName(operationShape, binding)}"
val inner = RuntimeType.forInlineFun("${fnName}_inner", "http_serde") {
it.rustBlock(
"pub fn ${fnName}_inner(headers: #T::header::ValueIter<http::HeaderValue>) -> Result<Option<#T>, #T::ParseError>",
"pub fn ${fnName}_inner(headers: #T::header::ValueIter<http::HeaderValue>) -> std::result::Result<Option<#T>, #T::ParseError>",
RuntimeType.http,
symbolProvider.toSymbol(model.expectShape(target.value.target)),
headerUtil
Expand All @@ -100,15 +100,15 @@ class ResponseBindingGenerator(protocolConfig: ProtocolConfig, private val opera
}
return RuntimeType.forInlineFun(fnName, "http_serde") { writer ->
writer.rustBlock(
"pub fn $fnName(header_map: &#T::HeaderMap) -> Result<#T, #T::ParseError>",
"pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>",
RuntimeType.http,
outputT,
headerUtil
) {
rust(
"""
let headers = #T::headers_for_prefix(&header_map, ${binding.locationName.dq()});
let out: Result<_, _> = headers.map(|(key, header_name)| {
let out: std::result::Result<_, _> = headers.map(|(key, header_name)| {
let values = header_map.get_all(header_name);
#T(values.iter()).map(|v| (key.to_string(), v.unwrap()))
}).collect();
Expand Down Expand Up @@ -137,15 +137,15 @@ class ResponseBindingGenerator(protocolConfig: ProtocolConfig, private val opera
return RuntimeType.forInlineFun(fnName, "http_serde") { rustWriter ->
if (binding.member.isStreaming(model)) {
rustWriter.rustBlock(
"pub fn $fnName(body: &mut #T) -> Result<#T, #T>",
"pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>",
RuntimeType.sdkBody(runtimeConfig),
outputT,
errorT
) {
deserializeStreamingBody(binding)
}
} else {
rustWriter.rustBlock("pub fn $fnName(body: &[u8]) -> Result<#T, #T>", outputT, errorT) {
rustWriter.rustBlock("pub fn $fnName(body: &[u8]) -> std::result::Result<#T, #T>", outputT, errorT) {
deserializePayloadBody(
binding,
errorT,
Expand Down Expand Up @@ -242,7 +242,7 @@ class ResponseBindingGenerator(protocolConfig: ProtocolConfig, private val opera
)
if (coreShape.hasTrait<MediaTypeTrait>()) {
rustTemplate(
"""let $parsedValue: Result<Vec<_>, _> = $parsedValue
"""let $parsedValue: std::result::Result<Vec<_>, _> = $parsedValue
.iter().map(|s|
#{base_64_decode}(s).map_err(|_|#{header}::ParseError)
.and_then(|bytes|String::from_utf8(bytes).map_err(|_|#{header}::ParseError))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class BasicAwsJsonGenerator(
operationWriter.rustTemplate(
"""
impl #{parse_strict} for $operationName {
type Output = Result<#{output}, #{error}>;
type Output = std::result::Result<#{output}, #{error}>;
fn parse(&self, response: &#{response}<#{bytes}>) -> Self::Output {
self.parse_response(response)
}
Expand Down Expand Up @@ -312,7 +312,7 @@ class BasicAwsJsonGenerator(
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(implBlockWriter)
Attribute.AllowUnused.render(implBlockWriter)
implBlockWriter.rustBlock(
"fn parse_response(&self, response: & #T<#T>) -> Result<#T, #T>",
"fn parse_response(&self, response: & #T<#T>) -> std::result::Result<#T, #T>",
RuntimeType.Http("response::Response"),
RuntimeType.Bytes,
symbolProvider.toSymbol(operationShape.outputShape(model)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class HttpBoundProtocolGenerator(
}
val serializer = RuntimeType.forInlineFun(fnName, "operation_ser") {
it.rustBlockTemplate(
"pub fn $fnName(payload: $ref #{Member}) -> Result<#{SdkBody}, #{BuildError}>",
"pub fn $fnName(payload: $ref #{Member}) -> std::result::Result<#{SdkBody}, #{BuildError}>",
"Member" to symbolProvider.toSymbol(member),
*codegenScope
) {
Expand Down Expand Up @@ -214,7 +214,7 @@ class HttpBoundProtocolGenerator(
rustTemplate(
"""
impl #{ParseStrict} for $operationName {
type Output = Result<#{O}, #{E}>;
type Output = std::result::Result<#{O}, #{E}>;
fn parse(&self, response: &#{Response}<#{Bytes}>) -> Self::Output {
if !response.status().is_success() && response.status().as_u16() != $successCode {
#{parse_error}(response)
Expand All @@ -240,7 +240,7 @@ class HttpBoundProtocolGenerator(
rustTemplate(
"""
impl #{ParseResponse}<#{SdkBody}> for $operationName {
type Output = Result<#{O}, #{E}>;
type Output = std::result::Result<#{O}, #{E}>;
fn parse_unloaded(&self, response: &mut http::Response<#{SdkBody}>) -> Option<Self::Output> {
// This is an error, defer to the non-streaming parser
if !response.status().is_success() && response.status().as_u16() != $successCode {
Expand Down Expand Up @@ -270,7 +270,7 @@ class HttpBoundProtocolGenerator(
return RuntimeType.forInlineFun(fnName, "operation_deser") {
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it)
it.rustBlockTemplate(
"pub fn $fnName(response: &#{Response}<#{Bytes}>) -> Result<#{O}, #{E}>",
"pub fn $fnName(response: &#{Response}<#{Bytes}>) -> std::result::Result<#{O}, #{E}>",
*codegenScope,
"O" to outputSymbol,
"E" to errorSymbol
Expand Down Expand Up @@ -324,7 +324,7 @@ class HttpBoundProtocolGenerator(
return RuntimeType.forInlineFun(fnName, "operation_deser") {
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it)
it.rustBlockTemplate(
"pub fn $fnName(response: &mut #{Response}<#{SdkBody}>) -> Result<#{O}, #{E}>",
"pub fn $fnName(response: &mut #{Response}<#{SdkBody}>) -> std::result::Result<#{O}, #{E}>",
*codegenScope,
"O" to outputSymbol,
"E" to errorSymbol
Expand All @@ -349,7 +349,7 @@ class HttpBoundProtocolGenerator(
return RuntimeType.forInlineFun(fnName, "operation_deser") {
Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it)
it.rustBlockTemplate(
"pub fn $fnName(response: &#{Response}<#{Bytes}>) -> Result<#{O}, #{E}>",
"pub fn $fnName(response: &#{Response}<#{Bytes}>) -> std::result::Result<#{O}, #{E}>",
*codegenScope,
"O" to outputSymbol,
"E" to errorSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SerdeJsonParserGenerator(protocolConfig: ProtocolConfig) : StructuredDataP
return RuntimeType.forInlineFun(fnName, "json_deser") {
it.rustTemplate(
"""
pub fn $fnName(inp: &[u8]) -> Result<#{Shape}, #{Error}> {
pub fn $fnName(inp: &[u8]) -> std::result::Result<#{Shape}, #{Error}> {
#{serde_json}::from_slice(inp)
}""",
*codegenScope, "Shape" to symbolProvider.toSymbol(shape)
Expand All @@ -55,7 +55,7 @@ class SerdeJsonParserGenerator(protocolConfig: ProtocolConfig) : StructuredDataP

return RuntimeType.forInlineFun(fnName, "json_deser") {
it.rustBlockTemplate(
"pub fn $fnName(inp: &[u8], mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>",
"pub fn $fnName(inp: &[u8], mut builder: #{Builder}) -> std::result::Result<#{Builder}, #{Error}>",
"Builder" to outputShape.builderSymbol(symbolProvider),
*codegenScope
) {
Expand Down Expand Up @@ -87,7 +87,7 @@ class SerdeJsonParserGenerator(protocolConfig: ProtocolConfig) : StructuredDataP
val fnName = errorShape.id.name.toString().toSnakeCase()
return RuntimeType.forInlineFun(fnName, "json_deser") {
it.rustBlockTemplate(
"pub fn $fnName(inp: &[u8], mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>",
"pub fn $fnName(inp: &[u8], mut builder: #{Builder}) -> std::result::Result<#{Builder}, #{Error}>",
"Builder" to errorShape.builderSymbol(symbolProvider),
*codegenScope
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class EndpointTraitBindingsTest {
)
it.implBlock(model.lookup("test#GetStatusInput"), sym) {
it.rustBlock(
"fn endpoint_prefix(&self) -> Result<#T::endpoint::EndpointPrefix, #T>",
"fn endpoint_prefix(&self) -> std::result::Result<#T::endpoint::EndpointPrefix, #T>",
TestRuntimeConfig.smithyHttp(),
TestRuntimeConfig.operationBuildError()
) {
Expand Down