pub struct WithholdingGenerator { /* private fields */ }Expand description
Generates withholding tax records for cross-border vendor payments.
For each payment where vendor_country != source_country:
- Looks up the treaty rate for the
(source_country, vendor_country)pair. - If a treaty exists, applies the treaty rate.
- If no treaty exists, applies the default withholding rate.
- Computes
withheld_amount = base_amount * applied_rate.
Domestic payments (where vendor_country == source_country) are excluded
from withholding and produce no records.
§Standard Treaty Rates
The with_standard_treaties
method loads a US-centric treaty network with service withholding rates for
major trading partners (GB, DE, JP, FR, SG, IN, BR).
Implementations§
Source§impl WithholdingGenerator
impl WithholdingGenerator
Sourcepub fn new(seed: u64, default_rate: Decimal) -> Self
pub fn new(seed: u64, default_rate: Decimal) -> Self
Creates a new withholding generator with the given seed and default rate.
The default rate is applied when no treaty rate exists for a given
country pair. A common value is 0.30 (30%).
Sourcepub fn add_treaty_rate(
&mut self,
source_country: &str,
vendor_country: &str,
rate: Decimal,
)
pub fn add_treaty_rate( &mut self, source_country: &str, vendor_country: &str, rate: Decimal, )
Adds a treaty rate for a specific country pair.
The rate is stored for the (source_country, vendor_country) direction.
Treaty rates are directional: a US-DE treaty rate applies when the US is
the source and DE is the vendor, but not vice versa.
Sourcepub fn with_standard_treaties(self) -> Self
pub fn with_standard_treaties(self) -> Self
Loads the standard US treaty network for service withholding rates.
Treaty rates (service withholding, US perspective):
- US-GB: 0% (services)
- US-DE: 0% (services)
- US-JP: 0% (services)
- US-FR: 0% (services)
- US-SG: 0% (services)
- US-IN: 15% (services)
- US-BR: 15% (services)
Sourcepub fn generate(
&mut self,
payments: &[(String, String, String, Decimal)],
source_country: &str,
) -> Vec<WithholdingTaxRecord>
pub fn generate( &mut self, payments: &[(String, String, String, Decimal)], source_country: &str, ) -> Vec<WithholdingTaxRecord>
Generate withholding records for cross-border payments.
Each payment is a tuple of (payment_id, vendor_id, vendor_country, amount).
Domestic payments (where vendor_country == source_country) are excluded.
For each cross-border payment:
- If a treaty rate exists for
(source_country, vendor_country), the treaty rate is applied. - Otherwise the
default_rateis applied. withheld_amount = base_amount * applied_rate.
Auto Trait Implementations§
impl Freeze for WithholdingGenerator
impl RefUnwindSafe for WithholdingGenerator
impl Send for WithholdingGenerator
impl Sync for WithholdingGenerator
impl Unpin for WithholdingGenerator
impl UnsafeUnpin for WithholdingGenerator
impl UnwindSafe for WithholdingGenerator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.