Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaSource without a static life time #117

Open
Rikorose opened this issue Mar 16, 2022 · 0 comments · May be fixed by #236
Open

MediaSource without a static life time #117

Rikorose opened this issue Mar 16, 2022 · 0 comments · May be fixed by #236
Milestone

Comments

@Rikorose
Copy link

So I want to use a media source that depends on an external life time 'a:

// My media source implementation:
struct DatasetMediaSource<'a> {
    r: hdf5::ByteReader<'a>, // Implements io::Read and io::Seek, but does not have a static life time
    size: u64,
}
impl<'a> DatasetMediaSource<'a> {
    fn new(ds: &'a hdf5::Dataset) -> Result<DatasetMediaSource<'a>> {
        Ok(DatasetMediaSource {
            r: ds.as_byte_reader()?,
            size: ds.size() as u64,
        })
    }
}
impl<'a> Read for DatasetMediaSource<'a> {
    fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
        self.r.read(buf)
    }
}
impl<'a> Seek for DatasetMediaSource<'a> {
    fn seek(&mut self, pos: SeekFrom) -> std::io::Result<u64> {
        self.r.seek(pos)
    }
}
impl<'a> MediaSource for DatasetMediaSource<'a> {
    fn is_seekable(&self) -> bool {
        true
    }

    fn byte_len(&self) -> Option<u64> {
        Some(self.size)
    }
}

However, MediaSourceStream requires a static life time:

// media_source_stream.rs
pub struct MediaSourceStream {
    /// The source reader.
    inner: Box<dyn MediaSource>, // same as: Box<dyn MediaSource + 'static>
   /// ...

Resulting in the error

let source = Box::new(DatasetMediaSource::new(&ds)?); // type: Box<dyn MediaSource + 'a>
                                              ^^^ borrowed value does not live long enough

Does someone have an idea, if I can use such a MediaSource?

@pdeljanov pdeljanov added this to the v0.6.0 milestone Feb 22, 2024
@a1phyr a1phyr linked a pull request Feb 27, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants