Skip to main content

DetectionOptions

Struct DetectionOptions 

Source
pub struct DetectionOptions {
    pub steps: usize,
    pub chunk_size: usize,
    pub threshold: f64,
    pub cp_isolation: Vec<String>,
    pub cp_exclusion: Vec<String>,
    pub preemptive_behaviour: bool,
    pub explain: bool,
    pub language_threshold: f64,
    pub enable_fallback: bool,
}
Expand description

Tuning knobs of from_bytes_with and detect.

The Default values match the Python package’s from_bytes. Override only the fields you need with struct update syntax:

use charset_norm::DetectionOptions;

let options = DetectionOptions {
    // Never consider these code pages, whatever the payload looks like.
    cp_exclusion: vec!["utf_7".into(), "hz".into()],
    // Look at more of the payload.
    steps: 10,
    ..DetectionOptions::default()
};
assert_eq!(options.chunk_size, 512);

Fields§

§steps: usize

Number of chunks sampled from the payload. Default: 5.

Chunks are spread evenly over the payload. When the payload is not longer than steps * chunk_size bytes, it is analysed whole, as a single chunk.

§chunk_size: usize

Size of each sampled chunk, in bytes. Default: 512.

Shrunk automatically when the payload is too short to hold steps chunks of this size.

§threshold: f64

Maximum acceptable mean chaos (see mess::mess_ratio) for a candidate encoding. Default: 0.2.

Lower values reject more candidates; raise it to accept noisier text.

§cp_isolation: Vec<String>

When not empty, only these encodings are tried. Default: empty.

Names may be any alias ("windows-1252", "UTF-8", …).

§cp_exclusion: Vec<String>

Encodings never tried, by any alias. Default: empty.

§preemptive_behaviour: bool

Favour an encoding declared inside the payload, such as <meta charset="..."> in HTML or a # coding: ... comment in Python sources. Default: true.

Only the first 8 KiB are searched. A declared encoding is tried right after any BOM-announced one, and detection stops there when it decodes the payload without any chaos.

§explain: bool

Log the chaos breakdown of every sampled chunk at Level::Trace. Default: false.

Only takes effect when cp_isolation names one or two encodings, to keep the output readable.

§language_threshold: f64

Minimum coherence (in [0, 1]) for a language to be reported. Default: 0.1.

§enable_fallback: bool

Fall back on ASCII, UTF-8 or a declared encoding when every candidate is rejected but one of those still decodes the payload. Default: true.

Without the fallback, text that is merely noisy can come back as no match at all (see is_binary).

Trait Implementations§

Source§

impl Clone for DetectionOptions

Source§

fn clone(&self) -> Self

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 DetectionOptions

Source§

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

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

impl Default for DetectionOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for DetectionOptions

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DetectionOptions

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.