# String lifetime issues

**URL:** <https://users.rust-lang.org/t/string-lifetime-issues/48950>\
**Category:** help\
**Created:** [September 18, 2020, 9:07am UTC](https://users.rust-lang.org/t/string-lifetime-issues/48950 "2020-09-18T09:07:31Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![2e71828](https://avatars.discourse-cdn.com/v4/letter/2/3e96dc/32.png) [@2e71828](https://users.rust-lang.org/u/2e71828)\
**Post date:** [September 18, 2020, 9:33am UTC](https://users.rust-lang.org/t/string-lifetime-issues/48950/3 "2020-09-18T09:33:12Z")

</div>

A key thing to remember is that tagging a struct with a lifetime (`<'a>`) only works when that data is stored outside the struct somewhere— Anytime you write `&'a mut Something<'a>` you’re [going to have trouble](https://users.rust-lang.org/t/how-to-resolve-error-e0499-cannot-borrow-as-mutable-more-than-once-at-a-time-in-this-case/48815/3).

There’s a few ways around this for your code:

- If all the snippets are literals, you can store them as `&'static str`’s instead of `String`s. ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=73e220bfbc17953f6ec7041f979f3b34))
- If they’re dynamically generated, you can use `Rc<str>` ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f6fe06fac315db6be1216d3426833acd))
- You can move the `SnippetHolder` into a local variable of `main` ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cb82242f1d2c64075fd9c1efc342cbee))

---

_[View the full topic](https://users.rust-lang.org/t/string-lifetime-issues/48950)._
