Skip to content

Commit

Permalink
Add #[inline] to trivial trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kijewski authored and djc committed Jan 6, 2022
1 parent 8b4cc66 commit 803d32c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions askama_shared/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
"type Target = {};",
parent_type.into_token_stream()
))?;
buf.writeln("#[inline]")?;
buf.writeln("fn deref(&self) -> &Self::Target {")?;
buf.writeln("&self._parent")?;
buf.writeln("}")?;
Expand All @@ -189,6 +190,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
// Implement `Display` for the given context struct.
fn impl_display(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
self.write_header(buf, "::std::fmt::Display", None)?;
buf.writeln("#[inline]")?;
buf.writeln("fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {")?;
buf.writeln("::askama::Template::render_into(self, f).map_err(|_| ::std::fmt::Error {})")?;
buf.writeln("}")?;
Expand All @@ -199,6 +201,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
fn impl_actix_web_responder(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
self.write_header(buf, "::actix_web::Responder", None)?;
buf.writeln("type Body = ::actix_web::body::BoxBody;")?;
buf.writeln("#[inline]")?;
buf.writeln(
"fn respond_to(self, _req: &::actix_web::HttpRequest) \
-> ::actix_web::web::HttpResponse<Self::Body> {",
Expand All @@ -211,6 +214,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
// Implement Axum's `IntoResponse`.
fn impl_axum_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
self.write_header(buf, "::askama_axum::IntoResponse", None)?;
buf.writeln("#[inline]")?;
buf.writeln(
"fn into_response(self)\
-> ::askama_axum::Response<::askama_axum::BoxBody> {",
Expand All @@ -224,6 +228,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
// Implement gotham's `IntoResponse`.
fn impl_gotham_into_response(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
self.write_header(buf, "::askama_gotham::IntoResponse", None)?;
buf.writeln("#[inline]")?;
buf.writeln(
"fn into_response(self, _state: &::askama_gotham::State)\
-> ::askama_gotham::Response<::askama_gotham::Body> {",
Expand Down Expand Up @@ -293,6 +298,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
Some(vec![param]),
)?;

buf.writeln("#[inline]")?;
buf.writeln(
"fn respond_to(self, _: &::askama_rocket::Request) \
-> ::askama_rocket::Result<'askama> {",
Expand All @@ -315,6 +321,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
)?;
buf.writeln(
"type Error = ::askama_tide::askama::Error;\n\
#[inline]\n\
fn try_into(self) -> ::askama_tide::askama::Result<::askama_tide::tide::Body> {",
)?;
buf.writeln(&format!("::askama_tide::try_into_body(&self, {:?})", &ext))?;
Expand All @@ -323,13 +330,15 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {

buf.writeln("#[allow(clippy::from_over_into)]")?;
self.write_header(buf, "Into<::askama_tide::tide::Response>", None)?;
buf.writeln("#[inline]")?;
buf.writeln("fn into(self) -> ::askama_tide::tide::Response {")?;
buf.writeln(&format!("::askama_tide::into_response(&self, {:?})", ext))?;
buf.writeln("}\n}")
}

fn impl_warp_reply(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
self.write_header(buf, "::askama_warp::warp::reply::Reply", None)?;
buf.writeln("#[inline]")?;
buf.writeln("fn into_response(self) -> ::askama_warp::warp::reply::Response {")?;
let ext = self.input.extension().unwrap_or("txt");
buf.writeln(&format!("::askama_warp::reply(&self, {:?})", ext))?;
Expand Down

0 comments on commit 803d32c

Please sign in to comment.