Skip to content

Commit

Permalink
Note record usage
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Dec 22, 2024
1 parent 2b7dd35 commit 9f1cf35
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ pub fn main() {
let unit_price = 10.0
let discount = 0.2

// Explicitly providing local variable names when calling the function.
// Using the regular label syntax
calculate_total_cost(
quantity: quantity,
unit_price: unit_price,
discount: discount,
)

// However, since our local variable names are identical to the argument
// labels, we can omit the variable names entirely and use shorthand label
// syntax.
// Using the shorthand syntax
calculate_total_cost(quantity:, unit_price:, discount:)
}

Expand All @@ -23,6 +21,5 @@ fn calculate_total_cost(
) -> Float {
let subtotal = quantity *. price
let discount = subtotal *. discount

subtotal -. discount
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
the variable names can be omitted when calling the function. This is known as
shorthand syntax for labels.
</p>
<p>The shorthand syntax can also be used for record constructor arguments.</p>

0 comments on commit 9f1cf35

Please sign in to comment.