pub struct CodeFormat {
pub prefix: Option<String>,
pub suffix: Option<String>,
pub separator: Option<char>,
pub separator_positions: Vec<usize>,
}Expand description
Code format options for prefix, suffix, and separators.
§Examples
use promocrypt_core::CodeFormat;
let format = CodeFormat::new()
.with_prefix("PROMO-")
.with_suffix("-2024")
.with_separator('-', vec![4, 8]);
assert_eq!(format.format("A3KF7NP2XM"), "PROMO-A3KF-7NP2-XM-2024");Fields§
§prefix: Option<String>Optional prefix prepended to code
suffix: Option<String>Optional suffix appended to code
separator: Option<char>Separator character
separator_positions: Vec<usize>Positions where separator is inserted (0-based, before the character at that position)
Implementations§
Source§impl CodeFormat
impl CodeFormat
Sourcepub fn is_default(&self) -> bool
pub fn is_default(&self) -> bool
Check if this is the default (empty) format.
Source§impl CodeFormat
impl CodeFormat
Sourcepub fn with_prefix(self, prefix: &str) -> Self
pub fn with_prefix(self, prefix: &str) -> Self
Set prefix.
Sourcepub fn with_suffix(self, suffix: &str) -> Self
pub fn with_suffix(self, suffix: &str) -> Self
Set suffix.
Sourcepub fn with_separator(self, sep: char, positions: Vec<usize>) -> Self
pub fn with_separator(self, sep: char, positions: Vec<usize>) -> Self
Set separator and positions.
Sourcepub fn strip(&self, formatted_code: &str) -> Option<String>
pub fn strip(&self, formatted_code: &str) -> Option<String>
Strip formatting from code to get base code.
Sourcepub fn total_length(&self, base_length: usize) -> usize
pub fn total_length(&self, base_length: usize) -> usize
Calculate expected total length of formatted code.
Sourcepub fn has_formatting(&self) -> bool
pub fn has_formatting(&self) -> bool
Check if any formatting is applied.
Trait Implementations§
Source§impl Clone for CodeFormat
impl Clone for CodeFormat
Source§fn clone(&self) -> CodeFormat
fn clone(&self) -> CodeFormat
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CodeFormat
impl Debug for CodeFormat
Source§impl Default for CodeFormat
impl Default for CodeFormat
Source§fn default() -> CodeFormat
fn default() -> CodeFormat
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for CodeFormat
impl<'de> Deserialize<'de> for CodeFormat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for CodeFormat
impl PartialEq for CodeFormat
Source§impl Serialize for CodeFormat
impl Serialize for CodeFormat
impl Eq for CodeFormat
impl StructuralPartialEq for CodeFormat
Auto Trait Implementations§
impl Freeze for CodeFormat
impl RefUnwindSafe for CodeFormat
impl Send for CodeFormat
impl Sync for CodeFormat
impl Unpin for CodeFormat
impl UnwindSafe for CodeFormat
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
Mutably borrows from an owned value. Read more