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:
C0D3 M4513R 2025-05-07 17:11:45 +02:00 committed by GitHub
parent 73ba176ad5
commit c31fce773e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -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,

View 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");
}