#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ContainerInfo {
format_name: String,
bit_rate: Option<u64>,
nb_streams: u32,
}
impl ContainerInfo {
#[must_use]
pub fn builder() -> ContainerInfoBuilder {
ContainerInfoBuilder::default()
}
#[must_use]
pub fn format_name(&self) -> &str {
&self.format_name
}
#[must_use]
pub fn bit_rate(&self) -> Option<u64> {
self.bit_rate
}
#[must_use]
pub fn nb_streams(&self) -> u32 {
self.nb_streams
}
}
#[derive(Debug, Default)]
pub struct ContainerInfoBuilder {
format_name: String,
bit_rate: Option<u64>,
nb_streams: u32,
}
impl ContainerInfoBuilder {
#[must_use]
pub fn format_name(mut self, name: impl Into<String>) -> Self {
self.format_name = name.into();
self
}
#[must_use]
pub fn bit_rate(mut self, br: u64) -> Self {
self.bit_rate = Some(br);
self
}
#[must_use]
pub fn nb_streams(mut self, n: u32) -> Self {
self.nb_streams = n;
self
}
#[must_use]
pub fn build(self) -> ContainerInfo {
ContainerInfo {
format_name: self.format_name,
bit_rate: self.bit_rate,
nb_streams: self.nb_streams,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn container_info_builder_sets_fields() {
let info = ContainerInfo::builder()
.format_name("mp4")
.bit_rate(1_000_000)
.nb_streams(3)
.build();
assert_eq!(info.format_name(), "mp4");
assert_eq!(info.bit_rate(), Some(1_000_000));
assert_eq!(info.nb_streams(), 3);
}
#[test]
fn bit_rate_none_when_not_set() {
let info = ContainerInfo::builder().format_name("mp3").build();
assert_eq!(info.bit_rate(), None);
}
#[test]
fn default_builder_produces_empty_info() {
let info = ContainerInfo::builder().build();
assert_eq!(info.format_name(), "");
assert_eq!(info.bit_rate(), None);
assert_eq!(info.nb_streams(), 0);
}
}