Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Advice to change function signature when aliases are involved

Here’s a scenario from earlier in this guide. The compiler advice is:

error[E0621]: explicit lifetime required in the type of `s`
 --> src/lib.rs:5:9
  |
5 |         Self(s)
  |         ^^^^^^^ lifetime `'a` required
  |
help: add explicit lifetime `'a` to the type of `s`
  |
4 |     fn new(s: &'a str) -> Node<'_> {
  |                ++

But this works just as well:

-        Self(s)
+        Node(s)

And you may even get the above compiler advice when implementing a trait, where you usually can’t change the signature.