I would suggest Simplification reference life-time in Rust
Consider the following code:
fn foo<'a, 'b>(s1: &'a Vec<u8>, s2: &'b Vec<u8>) -> &'a Vec<u8> {
println!("foo");
s1
}
struct DoStruct {
ll: u32
}
trait MyTrait<T> {
fn do_something(self) -> &T;
}
impl<'a> MyTrait<u32> for &'a DoStruct {
fn do_something(self) -> &'a u32 {
println!("do_something");
&self.ll
}
}
As we can see, there are lots of declared reference life-time Why we should every time declare reference life-time ?! It is lots of boilerplate code !!
Consider simpler solution:
fn foo(s1: &'a Vec<u8>, s2: &'b Vec<u8>) -> &'a Vec<u8> { // fn foo<'a, 'b>(s1: &'a Vec<u8>, s2: &'b Vec<u8>) -> &'a Vec<u8>
println!("foo");
s1
}
struct DoStruct {
ll: u32
}
trait MyTrait<T> {
fn do_something(self) -> &T;
}
impl MyTrait<u32> for &'a DoStruct { // the same as impl<'a> MyTrait<u32> for &'a DoStruct
fn do_something(self) -> &'a u32 {
println!("do_something");
&self.ll
}
}
Compiler in this example deduce declaration of reference life-time by itself !! But it is possible to declare it manually