pub struct Pid(/* private fields */);Expand description
A 13-bit MPEG-TS Packet Identifier.
Thin newtype over the wire u16, always in 0x0000..=0x1FFF (the
transport header field width, ISO/IEC 13818-1 §2.4.3.2). Construction never
masks a caller-supplied value: Pid::try_new rejects an out-of-range
one, Pid::from_wire_masked is the explicit parse-site constructor, and
Pid::from_const is the compile-time constructor for constants.
Implementations§
Source§impl Pid
impl Pid
Sourcepub const fn from_const(value: u16) -> Self
pub const fn from_const(value: u16) -> Self
Construct a constant Pid, failing compilation (a const panic)
when value exceeds Pid::MASK.
This is the constructor for well-known PIDs and table constants: a
mistyped literal is a build error, never a silently masked different
PID. Runtime values use Pid::try_new.
use mpeg_ts::pid::Pid;
const PMT: Pid = Pid::from_const(0x0100);
assert_eq!(PMT.value(), 0x0100);Sourcepub const fn from_wire_masked(value: u16) -> Self
pub const fn from_wire_masked(value: u16) -> Self
Construct a Pid from the low 13 bits of value, deliberately
discarding the rest: the explicit name for extracting the 13-bit PID
field out of a wider wire word (e.g. reserved(3) + PID(13)), where
masking is the specified behaviour. Use this only at parse sites, so a
caller-supplied value is never masked by accident; use
Pid::try_new for those and Pid::from_const for constants.
use mpeg_ts::pid::Pid;
// reserved(3) = 0b111 followed by PID 0x0100.
assert_eq!(Pid::from_wire_masked(0xE100).value(), 0x0100);
assert_eq!(Pid::try_new(0xE100).unwrap_err().value, 0xE100);Sourcepub const fn try_new(value: u16) -> Result<Self, PidOutOfRange>
pub const fn try_new(value: u16) -> Result<Self, PidOutOfRange>
Construct a Pid, rejecting any value above Pid::MASK (0x1FFF).
Use this at API boundaries that take a caller-supplied value.
§Errors
PidOutOfRange when value > 0x1FFF.