vapoursynth4_rs/frame/
format.rs

1use std::{
2    ffi::{CStr, c_char},
3    fmt::Display,
4    str,
5};
6
7use crate::ffi;
8
9pub type VideoFormat = ffi::VSVideoFormat;
10pub type AudioFormat = ffi::VSAudioFormat;
11
12pub(crate) struct FormatName {
13    pub buffer: [u8; 32],
14}
15
16impl FormatName {
17    pub fn new() -> Self {
18        Self { buffer: [0; 32] }
19    }
20
21    #[must_use]
22    pub fn as_str(&self) -> &str {
23        // SAFETY: The buffer is guaranteed to be alphanumeric or underscore and null-terminated.
24        unsafe {
25            str::from_utf8_unchecked(CStr::from_bytes_with_nul_unchecked(&self.buffer).to_bytes())
26        }
27    }
28
29    pub fn as_mut_ptr(&mut self) -> *mut c_char {
30        self.buffer.as_mut_ptr().cast()
31    }
32}
33
34impl Display for FormatName {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        f.write_str(self.as_str())
37    }
38}