Skip to main content

MimeConfig

Struct MimeConfig 

Source
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.

FieldLogical keyEnvironment keyDefaultFormat
Default MIME detectormime.detector.defaultQUBIT_MIME_DETECTOR_DEFAULTrepositoryProvider id, alias, or auto
MIME detector fallbacksmime.detector.fallbacksQUBIT_MIME_DETECTOR_FALLBACKSemptyList split on , or ;
Media stream classifiermime.media.stream.classifier.defaultQUBIT_MEDIA_STREAM_CLASSIFIER_DEFAULTffprobeClassifier selector
Precise detection switchmime.enable.precise.detectionQUBIT_MIME_ENABLE_PRECISE_DETECTIONtrueBoolean
Precise detection patternsmime.precise.detection.patternsQUBIT_MIME_PRECISE_DETECTION_PATTERNSwebm,oggExtension list
Ambiguous MIME mappingmime.ambiguous.mime.mappingQUBIT_MIME_AMBIGUOUS_MIME_MAPPINGwebm:video/webm,audio/webm;ogg:video/ogg,audio/oggext: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

Source

pub fn load() -> Self

Loads configuration from environment variables and defaults.

§Returns

Configuration used by default detector instances.

Source

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.

Source

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.

Source

pub fn set_default(config: Self)

Replaces the global default MIME configuration.

§Parameters
  • config: Configuration to use for future default instances.
Source

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.

Source

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.

Source

pub fn mime_detector_default(&self) -> &str

Gets the configured default MIME detector selector.

§Returns

Backend selector used by default detector wrappers.

Source

pub fn mime_detector_fallbacks(&self) -> &[String]

Gets fallback MIME detector selectors.

§Returns

Ordered fallback backend selectors.

Source

pub fn media_stream_classifier_default(&self) -> &str

Gets the configured default media stream classifier selector.

§Returns

Backend selector used by default classifier wrappers.

Source

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.

Source

pub fn precise_detection_patterns(&self) -> &HashSet<String>

Gets extensions requiring precise detection.

§Returns

Lowercase extension names without leading dots.

Source

pub fn ambiguous_mime_mapping(&self) -> &HashMap<String, [String; 2]>

Gets ambiguous extension mappings.

§Returns

Mapping from extension to [video_mime, audio_mime].

Trait Implementations§

Source§

impl Clone for MimeConfig

Source§

fn clone(&self) -> MimeConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MimeConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MimeConfig

Source§

fn default() -> Self

Loads default configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, D> IntoConfigDefault<T> for D
where D: IntoValueDefault<T>,

Source§

fn into_config_default(self) -> T

Converts this fallback value into T.
Source§

impl<T> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.