I have a struct with a reference, which is in turn a component of another struct. The borrow checker asks for an explicit lifetime which is already present. Everything seems to be annotated properly for lifetime pass-through, but I seem to be doing something wrong.
/// Additional data in full updates
#[derive(Debug, Clone, PartialEq, Default)]
pub struct UpdateAdditionalData<'a> {
foo: &'a [u8]
}
#[derive(Debug, Clone, PartialEq)]
pub struct UpdateData<'a> {
additional: UpdateAdditionalData<'a>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ObjectUpdateCompressedObjectData<'a> {
pub data: &'a [u8],
}
pub fn decodeobjectupdatecompressed2a(b: &[u8]) -> Result<UpdateData, &str> {
Ok(UpdateData{
additional: Default::default() })}
pub fn decodeobjectupdatecompressed<'a>(od: &'a ObjectUpdateCompressedObjectData) -> Result<UpdateData<'a>, &'static str> {
Ok(decodeobjectupdatecompressed2a(od.data)?)
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0621]: explicit lifetime required in the type of `od`
--> src/lib.rs:24:48
|
23 | pub fn decodeobjectupdatecompressed<'a>(od: &'a ObjectUpdateCompressedObjectData) -> Result<UpdateData<'a>, &'static str> {
| ------------------------------------ help: add explicit lifetime `'static` to the type of `od`: `&'a ObjectUpdateCompressedObjectData<'static>`
24 | Ok(decodeobjectupdatecompressed2a(od.data)?)
| ^ lifetime `'static` required
error: aborting due to previous error
For more information about this error, try `rustc --explain E0621`.
error: could not compile `playground`
To learn more, run the command again with --verbose.