3 ms·
fn is analogous to function in javascript. It takes the form `fn fnname<generics, generics>(argname: argtype) -> ReturnType` The "weird" 'a here is a generic l
by roblabla 7y ago
fn is analogous to function in javascript. It takes the form `fn fnname<generics, generics>(argname: argtype) -> ReturnType`
The "weird" 'a here is a generic lifetime. It basically says that the returned value (Term) must not outlive the input values (env and args).
A &[Term<'a>] is a slice of Term<'a>. You can think of a slice as if it was an array whose size is known at runtime.
A Result<Term<'a>, Error> is a type in the standard library used for error handling. It can either be an `Ok(Term)` or an `Err(Error)` depending on whether the function succeeded or not. (There is no special magic here, you can define your own type that can be "either" one or the other. They're called enums in Rust).
- thenewwazoo 7y agoJust a quick re-contextualization. I wouldn't say > "It basically says that the returned value (Term) must not outlive the input values (env and args)." It doesn't say that it must not, it says that it doesn't. Because lifetime information can only be inferred about callees and not callers, the lifetime annotation tells the compiler what it needs to know about the caller's environment. It tells the compiler "the lifetimes of these two things are tied together in my caller". The compiler can then use that information when the borrow checker is doing its magic. I've got an article written in my head about how to think about lifetimes in terms of visibility up and down the call stack.