Font::layout coerces lifetime for "str" parameter
The Font::layout
method currently forces the str
parameter's lifetime to be at least the font's lifetime, which makes it impossible to use it with a string created on the fly:
let vec_str: String = vec.iter().cloned().collect();
let glyphs: Vec<_> = font.layout(buffer_str.as_ref(), scale, offset).collect();
where vec
is a Vec<char>
, triggers a lifetime error:
error[E0597]: `vec_str` does not live long enough
--> src/render/mod.rs:33:35
|
23 | pub fn get_glyphs<'font>(vec: Vec<char>, font: &'font rusttype::Font<'font>) -> Vec<PositionedGlyph<'font>> {
| ----- lifetime `'font` defined here
...
33 | let glyphs: Vec<_> = font.layout(vec_str.as_ref(), scale, offset).collect();
| ------------^^^^^^^-------------------------
| | |
| | borrowed value does not live long enough
| argument requires that `vec_str` is borrowed for `'font`
...
38 | }
| - `vec_str` dropped here while still borrowed
Would there be a way to fix this, while keeping the guarantees brought by !140 (merged)?
Edited by Algorythmis