mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 13:00:57 +00:00

* 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>
33 lines
828 B
Rust
33 lines
828 B
Rust
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");
|
|
}
|