pub struct StringConversionOptions {
pub trim: bool,
pub blank_string_policy: BlankStringPolicy,
}Expand description
Controls normalization applied once before parsing a string source.
Trimming happens before blank detection. A value is considered blank when
it consists only of Unicode whitespace, even when trim is disabled;
BlankStringPolicy::Preserve returns the original untrimmed slice in that
case.
§Examples
use qubit_datatype::StringConversionOptions;
let options = StringConversionOptions::env_friendly();
assert_eq!(options.normalize(" value "), Ok("value"));
assert!(options.normalize(" ").is_err());Fields§
§trim: boolWhether strings are trimmed before conversion.
blank_string_policy: BlankStringPolicyHow blank strings are interpreted after optional trimming.
Implementations§
Source§impl StringConversionOptions
impl StringConversionOptions
Sourcepub const fn env_friendly() -> Self
pub const fn env_friendly() -> Self
Creates options suitable for environment-variable input.
The profile trims surrounding whitespace and treats a blank value as missing, matching common environment configuration conventions.
§Returns
Environment-friendly string normalization options.
Sourcepub fn with_blank_string_policy(self, policy: BlankStringPolicy) -> Self
pub fn with_blank_string_policy(self, policy: BlankStringPolicy) -> Self
Sourcepub fn normalize<'a>(
&self,
value: &'a str,
) -> Result<&'a str, StringNormalizationError>
pub fn normalize<'a>( &self, value: &'a str, ) -> Result<&'a str, StringNormalizationError>
Normalizes a string source according to these options.
§Parameters
value- Source string.
§Returns
Returns the normalized string.
§Errors
Returns StringNormalizationError::Missing when blank strings are
treated as missing, or StringNormalizationError::BlankRejected when
blank strings are rejected.
Trait Implementations§
Source§impl Clone for StringConversionOptions
impl Clone for StringConversionOptions
Source§fn clone(&self) -> StringConversionOptions
fn clone(&self) -> StringConversionOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more