API Reference¶
recipe-ratio exposes four free functions. All take and return f64 (grams, or
any consistent weight unit). No structs, no traits, no features to enable.
Every function is division-safe: a non-positive flour (or from_flour)
denominator returns 0.0, never a panic.
baker_percent¶
Baker's percentage of an ingredient relative to flour weight, with flour
fixed at 100%. Returns ingredient / flour × 100.
- Returns
0.0whenflour_grams <= 0.0(no division by zero). - Flour itself evaluates to
100.0.
use recipe_ratio::baker_percent;
assert!((baker_percent(300.0, 500.0) - 60.0).abs() < 1e-9); // 60% water
assert!((baker_percent(500.0, 500.0) - 100.0).abs() < 1e-9); // flour is 100%
assert!((baker_percent(10.0, 500.0) - 2.0).abs() < 1e-9); // 2% salt
assert_eq!(baker_percent(300.0, 0.0), 0.0); // safe on zero flour
hydration¶
Dough hydration — the baker's percentage of water, i.e.
water / flour × 100. This is the single number bakers use to describe how wet
a dough is. Thin: 55–60% (bagels, sandwich bread). Medium: 60–68% (lean
breads). High: 70–85% (ciabatta, focaccia).
Equivalent to baker_percent(water_grams, flour_grams); provided as a named
alias because hydration is the ratio bakers reach for first.
use recipe_ratio::hydration;
assert!((hydration(300.0, 500.0) - 60.0).abs() < 1e-9); // a 60% dough
assert!((hydration(400.0, 500.0) - 80.0).abs() < 1e-9); // a wet 80% dough
scale¶
Scale an ingredient weight when the flour in a recipe changes from
from_flour to to_flour, holding the ratio constant.
result = ingredient × (to_flour / from_flour)
- Returns
0.0whenfrom_flour <= 0.0. - Doubling the flour doubles every scaled ingredient; halving the flour halves them.
use recipe_ratio::scale;
// 300 g water at 500 g flour → scaled to a 1 kg flour batch
assert!((scale(300.0, 500.0, 1000.0) - 600.0).abs() < 1e-9); // doubled
assert!((scale(300.0, 500.0, 250.0) - 150.0).abs() < 1e-9); // halved
assert_eq!(scale(300.0, 0.0, 1000.0), 0.0); // safe
dough_weight¶
Total dough weight — the sum of every ingredient weight (flour + water + salt + …). Pass any slice of gram amounts.