Wrong number of life parameters: expected 1, found 0

I have very rude pointers in Rust. This code will not compile because: wrong number of lifetime parameters: expected 1, found 0 [E0107] . What does it mean?

 struct Planet<'a> { name: &'a str, radius_km: i32, surface_area_km2: i64, orbital_period_days: i32, distance_from_sun: i64 } fn mercury() -> Planet { Planet { name: "Mercury", radius_km: 2_440, surface_area_km2: 74_800_000, orbital_period_days: 88, distance_from_sun: 57_910_000 } } fn main() { let mercury = Box::new(mercury()); println!("{}",mercury.name) } 
+5
source share
1 answer

Saying that your definition for struct contains a type parameter, and therefore your function should be created.

 struct Planet<'a>{ name : &'a str, radius_km: i32, surface_area_km2: i64, orbital_period_days: i32, distance_from_sun: i64 } fn mercury<'a>()->Planet<'a>{ Planet{ name:"Mercudy", radius_km: 2_440, surface_area_km2: 74_800_000, orbital_period_days: 88, distance_from_sun: 57_910_000 } } fn main(){ let planet = mercury(); println!("{}", planet.name) } 
+6
source

Source: https://habr.com/ru/post/1215003/


All Articles