Skip to main content

media_tools/models/
media_profile_id.rs

1//! Stable identity for a family-managed media profile.
2use serde::{Deserialize, Serialize};
3use std::str::FromStr;
4use uuid::Uuid;
5
6/// Identifier for a media profile, independent of EME user identity.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(transparent)]
9pub struct MediaProfileId(Uuid);
10
11impl MediaProfileId {
12    pub fn new() -> Self {
13        Self(Uuid::new_v4())
14    }
15}
16
17impl Default for MediaProfileId {
18    fn default() -> Self {
19        Self::new()
20    }
21}
22
23impl std::fmt::Display for MediaProfileId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        self.0.fmt(f)
26    }
27}
28
29impl FromStr for MediaProfileId {
30    type Err = uuid::Error;
31
32    fn from_str(value: &str) -> Result<Self, Self::Err> {
33        Uuid::parse_str(value).map(Self)
34    }
35}