broadcast-core 0.1.1

Frozen wire-format contract for the rust-broadcast crates: symmetric Parse/Serialize traits, checked field-width helpers, MSB-first bit I/O, reserved-bit fields, media timescales, the shared error kinds and the CENC scheme identity. no_std + alloc.
Documentation
//! Named deployment profiles for the workspace's limit presets (#4766).
//!
//! Every `*Limits`, `*Bounds` and `*Timings` value in the workspace is the
//! caller's: no crate implements `Default` for one. A [`Profile`] is the one
//! sanctioned shortcut. A limit type that offers `for_profile(Profile)` builds
//! a complete value whose every number is a named, documented constant chosen
//! for that class of deployment; the caller then replaces any field with its
//! typed `with_*` setter.
//!
//! A profile sizes memory and waits only. It never chooses what happens to
//! damaged input: a preset delivers a damaged unit flagged, and dropping it
//! stays the caller's opt-in through the struct's own setter.

/// The class of deployment a limit preset is sized for.
///
/// Each later variant is sized for at least the work of the one before it:
/// for every capacity and byte bound, `Embedded <= Device <= Server <=
/// Headend`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Profile {
    /// One program on a device with a few hundred megabytes of memory: a
    /// 32-bit or wasm32 target carrying few elementary streams.
    Embedded,
    /// Single-service playback on a phone, tablet, television or desktop,
    /// with about thirty seconds of read-ahead under a byte cap.
    Device,
    /// A live origin or HLS server carrying several programs.
    Server,
    /// A whole multiplex with full service information: up to 2048 PIDs.
    Headend,
}

impl Profile {
    /// Every profile, smallest first.
    pub const ALL: [Profile; 4] = [
        Profile::Embedded,
        Profile::Device,
        Profile::Server,
        Profile::Headend,
    ];

    /// The profile's lower-case name.
    #[must_use]
    pub fn name(&self) -> &'static str {
        match self {
            Profile::Embedded => "embedded",
            Profile::Device => "device",
            Profile::Server => "server",
            Profile::Headend => "headend",
        }
    }

    /// The one of the four values that belongs to this profile, given in
    /// profile order (`embedded`, `device`, `server`, `headend`).
    #[must_use]
    pub const fn select<T: Copy>(self, embedded: T, device: T, server: T, headend: T) -> T {
        match self {
            Profile::Embedded => embedded,
            Profile::Device => device,
            Profile::Server => server,
            Profile::Headend => headend,
        }
    }
}

crate::impl_spec_display!(Profile);

#[cfg(test)]
mod tests {
    use super::Profile;
    use alloc::string::ToString;

    #[test]
    fn select_picks_the_profile_value() {
        let picked: [u8; 4] = Profile::ALL.map(|p| p.select(1, 2, 3, 4));
        assert_eq!(picked, [1, 2, 3, 4]);
    }

    #[test]
    fn names_and_display_agree() {
        let names = Profile::ALL.map(|p| p.name());
        assert_eq!(names, ["embedded", "device", "server", "headend"]);
        for p in Profile::ALL {
            assert_eq!(p.to_string(), p.name());
        }
    }
}