pub struct MimeConfig { /* private fields */ }Expand description
Runtime configuration for MIME detectors.
§Supported keys
Logical keys and environment-style keys are both accepted by
MimeConfig::from_config. Environment variables use the same names as the
environment-style keys.
| Field | Logical key | Environment key | Default | Format |
|---|---|---|---|---|
| Default MIME detector | mime.detector.default | QUBIT_MIME_DETECTOR_DEFAULT | repository | Provider id, alias, or auto |
| MIME detector fallbacks | mime.detector.fallbacks | QUBIT_MIME_DETECTOR_FALLBACKS | empty | List split on , or ; |
| Media stream classifier | mime.media.stream.classifier.default | QUBIT_MEDIA_STREAM_CLASSIFIER_DEFAULT | ffprobe | Classifier selector |
| Precise detection switch | mime.enable.precise.detection | QUBIT_MIME_ENABLE_PRECISE_DETECTION | true | Boolean |
| Precise detection patterns | mime.precise.detection.patterns | QUBIT_MIME_PRECISE_DETECTION_PATTERNS | webm,ogg | Extension list |
| Ambiguous MIME mapping | mime.ambiguous.mime.mapping | QUBIT_MIME_AMBIGUOUS_MIME_MAPPING | webm:video/webm,audio/webm;ogg:video/ogg,audio/ogg | ext:video,audio entries split on ; |
Detector fallback selection is performed by
MimeDetectorRegistry, not by this config
object. The config only stores the default selector and ordered fallback
names.
Implementations§
Source§impl MimeConfig
impl MimeConfig
Sourcepub fn load() -> Self
pub fn load() -> Self
Loads configuration from environment variables and defaults.
§Returns
Configuration used by default detector instances.
Sourcepub fn from_config(config: &Config) -> MimeResult<Self>
pub fn from_config(config: &Config) -> MimeResult<Self>
Creates MIME configuration from a config object.
Values are read with environment-friendly options, so both logical keys
such as mime.detector.default and environment-style keys such as
QUBIT_MIME_DETECTOR_DEFAULT are accepted. List values may be provided
as arrays or as scalar strings split on , and ;; empty items are
ignored.
§Examples
Configure a preferred native detector and a repository fallback:
use qubit_config::Config;
use qubit_mime::{
CONFIG_MIME_DETECTOR_DEFAULT,
CONFIG_MIME_DETECTOR_FALLBACKS,
MimeConfig,
MimeResult,
};
let mut source = Config::new();
source.set(CONFIG_MIME_DETECTOR_DEFAULT, "file")?;
source.set(CONFIG_MIME_DETECTOR_FALLBACKS, "repository")?;
let config = MimeConfig::from_config(&source)?;
assert_eq!("file", config.mime_detector_default());
assert_eq!(
["repository".to_owned()].as_slice(),
config.mime_detector_fallbacks(),
);§Parameters
config: Configuration object containing logical keys or environment variable style keys.
§Returns
Parsed MIME configuration.
§Errors
Returns MimeError::Config when a present
configuration value cannot be converted to the expected type.
Sourcepub fn from_env() -> MimeResult<Self>
pub fn from_env() -> MimeResult<Self>
Creates MIME configuration from process environment variables.
§Returns
Parsed MIME configuration.
§Errors
Returns MimeError::Config when the
environment cannot be represented by Config.
Sourcepub fn set_default(config: Self)
pub fn set_default(config: Self)
Replaces the global default MIME configuration.
§Parameters
config: Configuration to use for future default instances.
Sourcepub fn reload_default(config: &Config) -> MimeResult<()>
pub fn reload_default(config: &Config) -> MimeResult<()>
Reloads the global default MIME configuration from a config object.
§Parameters
config: Configuration object used to build the new default.
§Errors
Returns MimeError::Config when a present
configuration value cannot be converted to the expected type.
Sourcepub fn reload_default_from_env() -> MimeResult<()>
pub fn reload_default_from_env() -> MimeResult<()>
Reloads the global default MIME configuration from process environment.
§Errors
Returns MimeError::Config when the
environment cannot be represented by Config.
Sourcepub fn mime_detector_default(&self) -> &str
pub fn mime_detector_default(&self) -> &str
Gets the configured default MIME detector selector.
§Returns
Backend selector used by default detector wrappers.
Sourcepub fn mime_detector_fallbacks(&self) -> &[String]
pub fn mime_detector_fallbacks(&self) -> &[String]
Sourcepub fn media_stream_classifier_default(&self) -> &str
pub fn media_stream_classifier_default(&self) -> &str
Gets the configured default media stream classifier selector.
§Returns
Backend selector used by default classifier wrappers.
Sourcepub fn enable_precise_detection(&self) -> bool
pub fn enable_precise_detection(&self) -> bool
Tells whether precise media-stream detection is enabled.
§Returns
true when ambiguous media MIME types may be refined.
Sourcepub fn precise_detection_patterns(&self) -> &HashSet<String>
pub fn precise_detection_patterns(&self) -> &HashSet<String>
Gets extensions requiring precise detection.
§Returns
Lowercase extension names without leading dots.
Trait Implementations§
Source§impl Clone for MimeConfig
impl Clone for MimeConfig
Source§fn clone(&self) -> MimeConfig
fn clone(&self) -> MimeConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MimeConfig
impl Debug for MimeConfig
Auto Trait Implementations§
impl Freeze for MimeConfig
impl RefUnwindSafe for MimeConfig
impl Send for MimeConfig
impl Sync for MimeConfig
impl Unpin for MimeConfig
impl UnsafeUnpin for MimeConfig
impl UnwindSafe for MimeConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.