Skip to content

Commit

Permalink
Restore default
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Barber committed Oct 7, 2022
1 parent c1dc190 commit 12f9149
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class PythonApplicationGenerator(
fun render(writer: RustWriter) {
renderPyApplicationRustDocs(writer)
renderAppStruct(writer)
renderAppDefault(writer)
renderAppClone(writer)
renderPyAppTrait(writer)
renderAppImpl(writer)
Expand Down Expand Up @@ -129,6 +130,23 @@ class PythonApplicationGenerator(
)
}

private fun renderAppDefault(writer: RustWriter) {
writer.rustTemplate(
"""
impl Default for App {
fn default() -> Self {
Self {
handlers: Default::default(),
middlewares: #{SmithyPython}::PyMiddlewares::new::<#{Protocol}>(vec![]),
context: None,
workers: #{parking_lot}::Mutex::new(vec![]),
}
}
}
""",
)
}

private fun renderAppImpl(writer: RustWriter) {
writer.rustBlockTemplate(
"""
Expand Down Expand Up @@ -218,13 +236,7 @@ class PythonApplicationGenerator(
/// Create a new [App].
##[new]
pub fn new() -> Self {
Self {
handlers: Default::default(),
middlewares: #{SmithyPython}::PyMiddlewares::new::<#{Protocol}>(vec![]),
context: None,
workers: #{parking_lot}::Mutex::new(vec![]),
}
Self::default()
}
/// Register a context object that will be shared between handlers.
##[pyo3(text_signature = "(${'$'}self, context)")]
Expand Down

0 comments on commit 12f9149

Please sign in to comment.