Skip to main content

ffmpeg_the_third/codec/parameters/
borrowed_mut.rs

1use std::marker::PhantomData;
2use std::ptr::NonNull;
3
4use crate::ffi::*;
5use crate::{AsMutPtr, AsPtr};
6
7pub struct ParametersMut<'p> {
8    ptr: NonNull<AVCodecParameters>,
9    _marker: PhantomData<&'p mut AVCodecParameters>,
10}
11
12impl<'p> ParametersMut<'p> {
13    /// # Safety
14    ///
15    /// Ensure that
16    /// - `ptr` is either null or valid,
17    /// - the mutable borrow represented by `ptr` follows Rust borrow rules and
18    /// - the lifetime of the returned struct is correctly bounded.
19    pub unsafe fn from_raw(ptr: *mut AVCodecParameters) -> Option<Self> {
20        NonNull::new(ptr as *mut _).map(|ptr| Self {
21            ptr,
22            _marker: PhantomData,
23        })
24    }
25
26    /// Exposes a pointer to the contained [`AVCodecParameters`] for FFI purposes.
27    ///
28    /// This is guaranteed to be a non-null pointer.
29    pub fn as_ptr(&self) -> *const AVCodecParameters {
30        self.ptr.as_ptr()
31    }
32
33    /// Exposes a mutable pointer to the contained [`AVCodecParameters`] for FFI purposes.
34    ///
35    /// This is guaranteed to be a non-null pointer.
36    pub fn as_mut_ptr(&mut self) -> *mut AVCodecParameters {
37        self.ptr.as_ptr()
38    }
39}
40
41impl<'p> AsPtr<AVCodecParameters> for ParametersMut<'p> {
42    fn as_ptr(&self) -> *const AVCodecParameters {
43        self.as_ptr()
44    }
45}
46
47impl<'p> AsMutPtr<AVCodecParameters> for ParametersMut<'p> {
48    fn as_mut_ptr(&mut self) -> *mut AVCodecParameters {
49        self.as_mut_ptr()
50    }
51}