Relative Content

Tag Archive for rustlifetimeborrow-checker

Why this code results in multiple mutable borrow?

struct DcdWriter<‘a>(&’a mut [u8]); impl<‘a> DcdWriter<‘a> { fn write_len<T: num_traits::ToPrimitive>( &’a mut self, value: T, len: usize, ) -> &’a mut DcdWriter<‘a> { dcd_encode(value.to_u32().unwrap(), &mut self.0[0..len]); self.0 = &mut self.0[len..]; self } fn write_var<T: num_traits::ToPrimitive>(&’a mut self, value: &T) -> &’a mut DcdWriter<‘a> { let len = std::mem::size_of_val(&value); self.write_len((*value).to_u32().unwrap(), len) } fn write_simple<‘b: ‘a>(&’b mut […]

Second lifetime elision rule

The Rust book provides the following code to illustrate a valid function definition where explicit lifetimes are required: