You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow injecting methods with generic type parameters in the config object (#3274)
This is a follow-up to #3111. Currently, the injected methods are
limited to taking in concrete types. This PR allows for these methods to
take in generic type parameters as well.
```rust
impl<L, H, M> SimpleServiceConfigBuilder<L, H, M> {
pub fn aws_auth<C>(config: C) {
...
}
}
```
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
Copy file name to clipboardExpand all lines: codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGenerator.kt
"Injected config method `${it.name}` has generic bindings that use `L`, `H`, or `M` to refer to the generic types. This is not allowed. Invalid generic bindings: $lhmBindings",
372
+
)
373
+
}
374
+
val paramBindingsGenericTys = genericBindings.flatMap { it.genericTys }.toSet()
375
+
val paramBindingsGenericsWritable = rustTypeParameters(*paramBindingsGenericTys.toTypedArray())
332
376
333
377
// This produces a nested type like: "S<B, S<A, T>>", where
334
378
// - "S" denotes a "stack type" with two generic type parameters: the first is the "inner" part of the stack
@@ -345,7 +389,7 @@ class ServiceConfigGenerator(
345
389
rustTemplate(
346
390
"#{StackType}<#{Ty}, #{Acc:W}>",
347
391
"StackType" to stackType,
348
-
"Ty" to next.ty,
392
+
"Ty" to next.ty(),
349
393
"Acc" to acc,
350
394
)
351
395
}
@@ -362,12 +406,12 @@ class ServiceConfigGenerator(
362
406
writable {
363
407
rustTemplate(
364
408
"""
365
-
${serviceName}ConfigBuilder<
366
-
#{LayersReturnTy:W},
367
-
#{HttpPluginsReturnTy:W},
368
-
#{ModelPluginsReturnTy:W},
369
-
>
370
-
""",
409
+
${serviceName}ConfigBuilder<
410
+
#{LayersReturnTy:W},
411
+
#{HttpPluginsReturnTy:W},
412
+
#{ModelPluginsReturnTy:W},
413
+
>
414
+
""",
371
415
"LayersReturnTy" to layersReturnTy,
372
416
"HttpPluginsReturnTy" to httpPluginsReturnTy,
373
417
"ModelPluginsReturnTy" to modelPluginsReturnTy,
@@ -391,14 +435,15 @@ class ServiceConfigGenerator(
0 commit comments