pub struct EmploymentScenario {
pub hourly_rate: f32,
pub hours_per_week: f32,
pub filing_status: FilingStatus,
pub pretax_deductions: PreTaxDeductions,
pub posttax_deductions: PostTaxDeductions,
}Expand description
Represents an employment scenario with hourly rate, hours worked per week, filing status, and deductions.
Possible deductions avaialable are defined in the deductions module.
§Example
use paycheck_utils::FilingStatus;
use paycheck_utils::EmploymentScenario;
use paycheck_utils::PreTaxDeductions;
use paycheck_utils::PreTaxDeduction;
use paycheck_utils::PostTaxDeductions;
use paycheck_utils::PostTaxDeduction;
let new_job_scenario = EmploymentScenario::new(
30.0, // hourly rate
40.0, // hours per week
FilingStatus::Single, // filing status
PreTaxDeductions::new(vec![
PreTaxDeduction::Medical(Some(150.0)),
PreTaxDeduction::Dental(Some(50.0)),
PreTaxDeduction::Vision(Some(15.0)),
PreTaxDeduction::Traditional401K(Some(200.0)),
]), // pre-tax deductions
PostTaxDeductions::new(vec![PostTaxDeduction::Roth401K(Some(100.0))]) // post-tax deductions
);Fields§
§hourly_rate: f32§hours_per_week: f32§filing_status: FilingStatus§pretax_deductions: PreTaxDeductions§posttax_deductions: PostTaxDeductionsImplementations§
Source§impl EmploymentScenario
impl EmploymentScenario
pub fn new( hourly_rate: f32, hours_per_week: f32, filing_status: FilingStatus, pretax_deductions: PreTaxDeductions, posttax_deductions: PostTaxDeductions, ) -> Self
Sourcepub fn calculate_net_paycheck(&self) -> f32
pub fn calculate_net_paycheck(&self) -> f32
Calculates the net paycheck based on the employment scenario’s parameters.
The calculations consider gross income, pre-tax deductions, federal tax withholdings, Social Security, Medicare, and post-tax deductions.
The IRS defined constants used to make calculations (such as tax rates, thresholds and standard deductions) are defined in the utils module.
This IRS method and flow for calculating withholdings is based on the 2026 federal tax year guidelines and can be summarized as follows:
- Calculate gross paycheck on hourly rate and hours worked.
- Subtract pre-tax deductions from gross paycheck to get adjusted gross paycheck.
- Calculate federal tax withholdings based on annualized adjusted gross paycheck and filing status.
- Calculate Social Security and Medicare withholdings based on adjusted gross paycheck.
- Subtract federal tax withholdings, Social Security, Medicare, and post-tax deductions from adjusted gross paycheck to get net paycheck.
§Example
use paycheck_utils::PostTaxDeduction;
use paycheck_utils::PreTaxDeduction;
use paycheck_utils::FilingStatus;
use paycheck_utils::EmploymentScenario;
use paycheck_utils::PreTaxDeductions;
use paycheck_utils::PostTaxDeductions;
let pretax_deductions = PreTaxDeductions::new(vec![
PreTaxDeduction::Medical(Some(100.0)),
PreTaxDeduction::Dental(Some(50.0)),
PreTaxDeduction::Vision(Some(25.0)),
PreTaxDeduction::Traditional401K(Some(200.0)),
PreTaxDeduction::HSA(Some(150.0)),
]); // total = 525.0
let posttax_deductions = PostTaxDeductions::new(vec![
PostTaxDeduction::Roth401K(Some(100.0)),
PostTaxDeduction::VoluntaryLife(Some(30.0)),
]); // total = 130.0
let scenario = EmploymentScenario::new(
25.0, // hourly rate
45.0, // hours per week (bi-weekly paycheck = 90 hours [10 hours overtime])
FilingStatus::Single, // single filing status for standard deduction
pretax_deductions, // total = 525.0
posttax_deductions // total = 130.0
);
let net_paycheck = scenario.calculate_net_paycheck();
assert_eq!(net_paycheck, 1440.33);
// Explanation of calculation:
// 1. Gross Paycheck: (25.0 * 80) + (25.0 * 10 * 1.5) = 2000.0 + 375.0 = 2375.0
// 2. Adjusted Gross Paycheck: 2375.0 - 525.0 = 1850.0 (after pre-tax deductions)
// 3. Federal Withholding (annualized AGP = 1850.0 * 26 = 48100.0): Using 2026 tax brackets for Single filer:
// - 10% on first 12,400 = 12,400 * 0.10 = 1,240.0
// - 12% on amount over 12,400 up to 50,400 = (48,100.0 - 12,400.0) * 0.12 = 4,290.0
// - Total annual federal tax = 1,240.0 + 4,290.0 = 5,530.0
// - Bi-weekly federal withholding = 5,530.0 / 26 = 212.69
// 4. Social Security Withholding: 1850.0 * 0.062 = 114.70
// 5. Medicare Withholding: 1850.0 * 0.0145 = 26.83
// 6. Post-Tax Deductions: 100.0 + 30.0 = 130.0
// 7. Total Deductions: 212.69 + 114.70 + 26.83 + 130.0 = 484.22
// 8. Net Paycheck: 1850.0 - 212.69 - 114.70 - 26.83 - 130.0 = 1440.33§Returns
An f32 representing the calculated net paycheck amount.
§Panics
This function does not explicitly panic, but it assumes that the input values (hourly rate, hours worked, deductions) are valid and reasonable.
§Errors
This function does not return errors, but invalid input values may lead to incorrect calculations.
§Notes
The calculations are based on the 2026 federal tax year guidelines and may need to be updated for future tax years.