Skip to content

zerocopy 'static lifetime issue for mapping raw data to rust structures #2262

Closed Answered by valoh
valoh asked this question in Q&A
Discussion options

You must be logged in to vote

ok, I think I somewhat understand the problem now, the self-referential struct seem to be a problem which can be solved via self_cell. at least this compiles:

#[derive(Debug)]
struct LoadedFileView<'a> {
    pub header: &'a Header,
    pub sections_info: &'a Sections,
}

self_cell!(
    struct LoadedFile {
        owner: Vec<u8>,

        #[covariant]
        dependent: LoadedFileView,
    }

    impl {Debug}
);


impl LoadedFile {

    fn from(data: Vec<u8>) -> Result<LoadedFile> {
        LoadedFile::try_new(
            data,
            |data| {
                let mut offset = 0;
                let bytes = size_of::<Header>();

                let header = Header::ref_from_bytes(&da…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by valoh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants