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
  |
4 |     fn new(s: &str) -> Node<'_> {
  |               ---- help: add explicit lifetime `'a` to the type of `s`: `&'a str`
5 |         Self(s)
  |         ^^^^^^^ lifetime `'a` required

But this works just as well:

-        Self(s)
+        Node(s)

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