ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
//! The VIDEO track's codec seat.

use mediaframe::codec::VideoCodec as Foreign;

/// **What a video track's bytes are encoded with** — an FFmpeg video codec name in the lowercase
/// canon, or the open escape for one this build's roster does not carry.
///
/// The citizen wrapping [`mediaframe::codec::VideoCodec`], which is where the roster, the escape
/// and the ASCII fold all live. What this type adds is the right to give them a wire face, a filter
/// and a storage shape — the rights the orphan rule reserves to the crate owning the type, which is
/// why the newtype exists at all.
///
/// # Every string is a value, and that is the vocabulary rather than this type
///
/// [`new`](Self::new) cannot fail. `h264` names a codec, `Some Codec 9000` names one this build has
/// never heard of, and both are values — the second in the escape arm, losslessly. What separates
/// them is [`is_registered`](Self::is_registered), which is the question the absent refusal would
/// have been asking.
///
/// Refusing the unknown one would be the worse bargain by some distance, and it is the same bargain
/// [`Language`](crate::primitives::lang::Language) states for an unregistered subtag: the FFmpeg
/// table gains codecs, a generated roster is a snapshot, and a container in the wild carries
/// whatever its muxer wrote. Refusing would make a file unindexable because of a table
/// `mediaframe` last regenerated at n9.0.
///
/// # Equality is the CANONICAL slug, and the door is what makes that true
///
/// `VideoCodec::new("H264") == VideoCodec::new("h264")`, because the door folds and both hold the
/// named `h264`. The fold happens ONCE, at construction, so a stored column is canonical and
/// storage equality IS value equality: `WHERE "codec" = 'h264'` finds the row an `H264` tag
/// produced.
///
/// It holds against the upstream value too, which is the case that needs saying:
/// [`From<mediaframe::codec::VideoCodec>`](From) re-runs the slug table, so a
/// `mediaframe::codec::VideoCodec::other("h264")` — an escape arm holding a name the roster
/// already spells, which upstream admits and compares unequal to the named variant — becomes the
/// named variant on the way in. No second spelling of one codec exists inside this type.
///
/// # Ordering is ALPHABETICAL over that slug
///
/// `av1 < h264 < prores`. It orders the SPELLINGS and says nothing about the codecs — see the
/// module note, where the bargain is argued and the agreement with the `TEXT` column's own order is
/// what earns it a cursor seat.
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct VideoCodec(Foreign);

impl VideoCodec {
  /// Read a video codec name, WIDE — any case, known or not.
  ///
  /// The ONE door in. Every other route to a value of this type — [`FromStr`](core::str::FromStr),
  /// the GraphQL scalar, the column decode, the cursor read and the conversion from the upstream
  /// value — goes through here, so there is one fold and one table lookup in the house.
  ///
  /// It is total: a name the roster does not carry lands in the escape arm, ASCII-folded to the
  /// lowercase canon.
  #[inline]
  #[must_use]
  pub fn new(text: &str) -> Self {
    // `from_str` is `Infallible` upstream, and the `unwrap_or_else` is how that is spent without a
    // panic path: the closure takes an uninhabited value, so there is nothing here to fire.
    Self(text.parse().unwrap_or_else(|never| match never {}))
  }

  /// The wrapped upstream value, borrowed — the road to the roster's own `match`, its
  /// `IsVariant` predicates and everything else `mediaframe` publishes on it.
  #[inline]
  #[must_use]
  pub const fn get(&self) -> &Foreign {
    &self.0
  }

  /// The wrapped upstream value, owned. Canonical, the door having made it so.
  #[inline]
  #[must_use]
  pub fn into_inner(self) -> Foreign {
    self.0
  }

  /// The canonical slug — the text this value stores as, pages by, and crosses the wire as.
  #[inline]
  #[must_use]
  pub fn as_str(&self) -> &str {
    self.0.as_str()
  }

  /// Whether this build's roster CARRIES this codec, as against holding it in the open escape.
  ///
  /// `true` for `h264`, `false` for a name FFmpeg n9.0 did not have. It is the one question that is
  /// actually about the table rather than about the value, and the honest form of the check a
  /// fallible door would have been pretending to make — see the module note.
  ///
  /// The roster ITSELF is not restated here: it is
  /// [`mediaframe::codec::VideoCodec::ROSTER`](mediaframe::codec::VideoCodec#associatedconstant.ROSTER),
  /// and a citizen republishing its upstream's list would be a second copy to keep in step.
  #[inline]
  #[must_use]
  pub fn is_registered(&self) -> bool {
    !self.0.is_other()
  }
}

super::codec_citizen!(
  VideoCodec,
  mediaframe::codec::VideoCodec,
  VideoCodecWire,
  "VideoCodecFilter"
);

#[cfg(test)]
mod tests;