Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the rationale for not being able to use the outer type parameter within an inner function?

Tags:

I'm trying to create a recursive inner function that will print all elements in a linked list:

 fn print_stack(&self) {
    fn print_nodes(head: &Option<Box<Node<T>>>) {
        match head {
            Some(ref p) => {
                println!("{:?}",p.data);
                print_nodes(head.next);
            },
        }
   };
   print_nodes(&self.head);
}

The compiler generates the following error

can't use type parameters from outer function; try using a local  type parameter instead.

Why is this an error?