Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • R rusttype
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 22
    • Issues 22
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • redox-os
  • rusttype
  • Issues
  • #151
Closed
Open
Created May 22, 2020 by Algorythmis@Algorythmis

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 May 22, 2020 by Algorythmis
Assignee
Assign to
Time tracking