mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 04:50:40 +00:00
Relax Sized constraint on impl FastWritable for Cow
(#432)
* Add test to ensure `Cow<'_, str>` implements `FastWritable` * Relax Sized constraint on `impl FastWritable for Cow` * Run rustfmt Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> * Put "test" in a const block. * Update cow_str_implements_fast_writable.rs Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com> --------- Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Co-authored-by: René Kijewski <Kijewski@users.noreply.github.com>
This commit is contained in:
parent
73ba176ad5
commit
c31fce773e
@ -415,7 +415,7 @@ const _: () = {
|
||||
}
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
impl<T: FastWritable + alloc::borrow::ToOwned> FastWritable for alloc::borrow::Cow<'_, T> {
|
||||
impl<T: FastWritable + alloc::borrow::ToOwned + ?Sized> FastWritable for alloc::borrow::Cow<'_, T> {
|
||||
#[inline]
|
||||
fn write_into<W: fmt::Write + ?Sized>(
|
||||
&self,
|
||||
|
32
testing/tests/cow_str_implements_fast_writable.rs
Normal file
32
testing/tests/cow_str_implements_fast_writable.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Display;
|
||||
|
||||
use askama::{FastWritable, Template};
|
||||
|
||||
#[test]
|
||||
fn test_cows() {
|
||||
// This test ensures that Cow is FastWritable.
|
||||
// Every expression needs to implement fmt::Display, even if the FastWritable path
|
||||
// is going to be used.
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(source = "{{ bull }} + {{ cow }} = {{ calf }}", ext = "txt")]
|
||||
struct Cattle<A, B, C>
|
||||
where
|
||||
A: FastWritable + Display,
|
||||
B: FastWritable + Display,
|
||||
C: FastWritable + Display,
|
||||
{
|
||||
bull: A,
|
||||
cow: B,
|
||||
calf: C,
|
||||
}
|
||||
|
||||
let calf = "calf".to_owned();
|
||||
let t = Cattle {
|
||||
bull: Cow::Borrowed("bull"),
|
||||
cow: Cow::<str>::Owned("cow".to_owned()),
|
||||
calf: Cow::Borrowed(&calf),
|
||||
};
|
||||
assert_eq!(t.render().unwrap(), "bull + cow = calf");
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user