From 5cfef325b03b25ad96d6c229a5ec3fd6a32f700d Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 15 Dec 2021 14:08:45 +0100 Subject: Use a separate trait for object safety (#579) This is relatively major change to the main trait's API. For context, I always started from the concept of monomorphized traits, but later several contributors asked about object safety. At that point I made `Template` object-safe, and then even later added a `SizedTemplate` to make some things easier for people who don't need object safety. However, having object-safety in the primary trait is bad for performance (a substantial number of calls into the virtual `Write` trait is relatively slow), and I don't think those who don't need object safety should pay for the cost of having it. Additionally, I feel using associated consts for the extension and size hint is more idiomatic than having accessor methods. I don't know why I didn't use these from the start -- maybe associated consts didn't exist yet, or I didn't yet know how/when to use them. Askama is pretty old at this point... --- testing/tests/ext.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'testing/tests/ext.rs') diff --git a/testing/tests/ext.rs b/testing/tests/ext.rs index 5ed4e72..7a494fa 100644 --- a/testing/tests/ext.rs +++ b/testing/tests/ext.rs @@ -8,7 +8,7 @@ struct PathHtml; fn test_path_ext_html() { let t = PathHtml; assert_eq!(t.render().unwrap(), "foo.html"); - assert_eq!(t.extension(), Some("html")); + assert_eq!(PathHtml::EXTENSION, Some("html")); } #[derive(Template)] @@ -19,7 +19,7 @@ struct PathJinja; fn test_path_ext_jinja() { let t = PathJinja; assert_eq!(t.render().unwrap(), "foo.jinja"); - assert_eq!(t.extension(), Some("jinja")); + assert_eq!(PathJinja::EXTENSION, Some("jinja")); } #[derive(Template)] @@ -30,7 +30,7 @@ struct PathHtmlJinja; fn test_path_ext_html_jinja() { let t = PathHtmlJinja; assert_eq!(t.render().unwrap(), "foo.html.jinja"); - assert_eq!(t.extension(), Some("html")); + assert_eq!(PathHtmlJinja::EXTENSION, Some("html")); } #[derive(Template)] @@ -41,7 +41,7 @@ struct PathHtmlAndExtTxt; fn test_path_ext_html_and_ext_txt() { let t = PathHtmlAndExtTxt; assert_eq!(t.render().unwrap(), "foo.html"); - assert_eq!(t.extension(), Some("txt")); + assert_eq!(PathHtmlAndExtTxt::EXTENSION, Some("txt")); } #[derive(Template)] @@ -52,7 +52,7 @@ struct PathJinjaAndExtTxt; fn test_path_ext_jinja_and_ext_txt() { let t = PathJinjaAndExtTxt; assert_eq!(t.render().unwrap(), "foo.jinja"); - assert_eq!(t.extension(), Some("txt")); + assert_eq!(PathJinjaAndExtTxt::EXTENSION, Some("txt")); } #[derive(Template)] @@ -63,5 +63,5 @@ struct PathHtmlJinjaAndExtTxt; fn test_path_ext_html_jinja_and_ext_txt() { let t = PathHtmlJinjaAndExtTxt; assert_eq!(t.render().unwrap(), "foo.html.jinja"); - assert_eq!(t.extension(), Some("txt")); + assert_eq!(PathHtmlJinjaAndExtTxt::EXTENSION, Some("txt")); } -- cgit