E0106: expected 2 lifetime parameters

ok, I seem to exhaust Google again...

trying to compile this:

fn find_children_by_tagname<'a, 'b>(node: &'a Node, path: Vec<&'b str>) -> Result<Vec<&'a Node>, String> {
    if path.len() > 0 {
        let mut res: Vec<&Node> = Vec::new();
        for child in node.children().
            filter(|n| n.tag_name().name().eq(path.get(0))) {
            if path.len() > 1 {
                if let Ok(&mut vec) = find_children_by_tagname(&child, path[1..].to_owned()) {
            } else {
    } else {

(and many other variations, this one above is just the latest and to me it looks most plausible)
leads to this:

error[E0106]: missing lifetime specifiers
 --> src\parser.rs:6:91
6 | fn find_children_by_tagname<'a, 'b>(node: &'a Node, path: Vec<&'b str>) -> Result<Vec<&'a Node>, String> {
  |                                                                                           ^^^^ expected 2 lifetime parameters


PS: I pretty much suspect that the code will not compile as such anyway, due to mess with owned Vec and whatnot, but this "expected 2 lifetime parameters" is driving me nuts already ... I can not even find HOW ON EARTH ONE COULD SPECIFY THOSE ??

How is Node defined? From the message, it appears to need lifetime parameters too, like one Node<'x> or two Node<'x, 'y>. These may be related to your 'a and/or 'b lifetimes, but I can't tell from context.

Node is from roxmltree crate, the definition is

/// A node.
#[derive(Clone, Copy)]
pub struct Node<'a, 'input: 'a> {
    /// Node ID.
    id: NodeId,

    /// Tree containing the node.
    doc: &'a Document<'input>,

    d: &'a NodeData<'input>,

I still have no clue how that might help me resolve the issue (( I can't figure out how to specify the second lifetime parameter value in the output signature

oh no, I did ! although I don't yet really understand the implications but this seems to make compiler happy about the function declaration, at least!:

fn find_children_by_tagname<'a, 'input: 'a>(node: &'a Node, path: Vec<&'input str>) -> Result<Vec<&'a Node<'a, 'input>>, String> {

thanks, @cuviper!

now, what's the mechanism to propose updates to the Rust book ? @steveklabnik

Please file an issue!

1 Like