Skip to content

Commit

Permalink
refactor: remove utils
Browse files Browse the repository at this point in the history
  • Loading branch information
d-kuen committed May 3, 2024
1 parent 4875d59 commit 7917c46
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{utils::init_vec, xml::XmlElement};
use crate::xml::XmlElement;

#[derive(Default)]
pub struct Address<'a> {
Expand Down Expand Up @@ -34,13 +34,13 @@ impl<'a> Address<'a> {
}

pub fn with_phone(mut self, phone_number: &'a str) -> Self {
let phone_numbers = self.phone.get_or_insert_with(init_vec);
let phone_numbers = self.phone.get_or_insert_with(Vec::new);
phone_numbers.push(phone_number);
self
}

pub fn with_email(mut self, email_address: &'a str) -> Self {
let email_addresses = self.email.get_or_insert_with(init_vec);
let email_addresses = self.email.get_or_insert_with(Vec::new);
email_addresses.push(email_address);
self
}
Expand Down
4 changes: 2 additions & 2 deletions src/biller.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
address::Address, contact::Contact, identification::FurtherIdentification,
order_reference::OrderReference, utils::init_vec, xml::XmlElement,
order_reference::OrderReference, xml::XmlElement,
};

#[derive(Default)]
Expand All @@ -24,7 +24,7 @@ impl<'a> Biller<'a> {
mut self,
further_identification: FurtherIdentification<'a>,
) -> Self {
let fi = self.further_identification.get_or_insert_with(init_vec);
let fi = self.further_identification.get_or_insert_with(Vec::new);
fi.push(further_identification);
self
}
Expand Down
6 changes: 3 additions & 3 deletions src/contact.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{utils::init_vec, xml::XmlElement};
use crate::xml::XmlElement;

#[derive(Default)]
pub struct Contact<'a> {
Expand All @@ -22,13 +22,13 @@ impl<'a> Contact<'a> {
}

pub fn with_phone(mut self, phone_number: &'a str) -> Self {
let phone_numbers = self.phone.get_or_insert_with(init_vec);
let phone_numbers = self.phone.get_or_insert_with(Vec::new);
phone_numbers.push(phone_number);
self
}

pub fn with_email(mut self, email_address: &'a str) -> Self {
let email_addresses = self.email.get_or_insert_with(init_vec);
let email_addresses = self.email.get_or_insert_with(Vec::new);
email_addresses.push(email_address);
self
}
Expand Down
4 changes: 2 additions & 2 deletions src/invoice_recipient.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
address::Address, contact::Contact, identification::FurtherIdentification,
order_reference::OrderReference, utils::init_vec, xml::XmlElement,
order_reference::OrderReference, xml::XmlElement,
};

#[derive(Default)]
Expand All @@ -24,7 +24,7 @@ impl<'a> InvoiceRecipient<'a> {
mut self,
further_identification: FurtherIdentification<'a>,
) -> Self {
let fi = self.further_identification.get_or_insert_with(init_vec);
let fi = self.further_identification.get_or_insert_with(Vec::new);
fi.push(further_identification);
self
}
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod order_reference;
pub mod payment_method;
pub mod reduction_and_surcharge;
pub mod tax;
pub mod utils;
pub mod xml;

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/reduction_and_surcharge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rust_decimal::Decimal;

use crate::{decimal::CloneAndRescale, utils::init_vec, xml::XmlElement};
use crate::{decimal::CloneAndRescale, xml::XmlElement};

pub enum ReductionAndSurchargeValue {
Percentage(Decimal),
Expand Down Expand Up @@ -147,13 +147,13 @@ impl<'a> ReductionAndSurchargeListLineItemDetails<'a> {
}

pub fn with_reduction(mut self, reduction: ReductionListLineItem<'a>) -> Self {
let reductions = self.reduction_list_line_items.get_or_insert_with(init_vec);
let reductions = self.reduction_list_line_items.get_or_insert_with(Vec::new);
reductions.push(reduction);
self
}

pub fn with_surcharge(mut self, surcharge: SurchargeListLineItem<'a>) -> Self {
let surcharges = self.surcharge_list_line_items.get_or_insert_with(init_vec);
let surcharges = self.surcharge_list_line_items.get_or_insert_with(Vec::new);
surcharges.push(surcharge);
self
}
Expand Down
3 changes: 0 additions & 3 deletions src/utils.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/xml.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use once_cell::sync::Lazy;
use regex::Regex;

use crate::utils::init_vec;

static XML_ESCAPE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("[&\"'<>]").unwrap());

fn xml_escape(s: impl AsRef<str>) -> String {
Expand Down Expand Up @@ -75,7 +73,7 @@ impl<'a> XmlElement<'a> {
value: Box::new(value),
};

self.attrs.get_or_insert_with(init_vec).push(attr);
self.attrs.get_or_insert_with(Vec::new).push(attr);

self
}
Expand Down

0 comments on commit 7917c46

Please sign in to comment.