pub struct Registry { /* private fields */ }Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Self
pub fn register_codec(&mut self, codec: Arc<dyn Codec>, meta: FormatMeta)
pub fn register_container( &mut self, container: Arc<dyn Container>, meta: FormatMeta, )
pub fn codec(&self, id: FormatId) -> Option<&Arc<dyn Codec>>
pub fn container(&self, id: FormatId) -> Option<&Arc<dyn Container>>
Sourcepub fn require_codec(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
pub fn require_codec(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
Like Self::codec but yields FormatNotEnabled (exit 3), which is how
a caller distinguishes “wrong build” from “broken file”.
Sourcepub fn require_encoder(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
pub fn require_encoder(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
The codec for id, if this build has it and it can encode.
Separate from Self::require_codec because a codec that cannot encode
is a normal thing to have: the pure-Rust zstd and xz fallbacks let a
build with no C toolchain still read those formats. Without this check
the caller reaches encoder() on such a codec, and the natural body for
that method is a panic — reachable straight from a command line.
Sourcepub fn require_decoder(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
pub fn require_decoder(&self, id: FormatId) -> Result<&Arc<dyn Codec>>
The codec for id, if this build has it and it can decode.
pub fn require_container(&self, id: FormatId) -> Result<&Arc<dyn Container>>
Sourcepub fn require_container_writer(
&self,
id: FormatId,
) -> Result<&Arc<dyn Container>>
pub fn require_container_writer( &self, id: FormatId, ) -> Result<&Arc<dyn Container>>
The container for id, if this build has it and it can write.
Self::require_encoder’s container-side twin, and it exists for the
same reason that one does: without it a caller reaches create() on a
container that cannot write, and the natural body for that method is a
panic — reachable straight from a command line.
Phase 3b introduced the first read-only CONTAINERS (LHA, ARJ) and this
gate did not exist, so ContainerCaps::write was read by no caller at
all and each adapter hand-rolled its own Error::Unsupported refusal.
That was harmless only because both happened to return Err, and it
left one contract speaking three sentences: unsupported: LHA/LZH is read-only in this build from a container against `compress` can be read but not written by this build from a codec, for the identical
user action at the identical exit code. The refusal now comes from the
registry for codecs and containers alike, in one sentence, and each
trait method keeps its own Err as an unreachable backstop rather
than as the thing a user actually meets.
Sourcepub fn by_extension(&self, ext: &str) -> Option<FormatId>
pub fn by_extension(&self, ext: &str) -> Option<FormatId>
Extension lookup. Accepts "gz" or ".gz", any case.
Sourcepub fn match_magic(&self, prefix: &[u8]) -> Vec<FormatId>
pub fn match_magic(&self, prefix: &[u8]) -> Vec<FormatId>
Every format whose magic matches prefix. Empty rather than a guess.
Sourcepub fn priority_of(&self, id: FormatId) -> i16
pub fn priority_of(&self, id: FormatId) -> i16
The priority of a registered format, or 0 if unknown.