From e35482fb824bc3a1d2a7bf98baf84be9252b0890 Mon Sep 17 00:00:00 2001 From: Boris Egorov Date: Thu, 30 Jun 2016 17:43:43 +0600 Subject: [PATCH] chapter3: Fix multiple-argument functions signatures --- nostarch/chapter3.md | 4 ++-- src/ch03-03-functions.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nostarch/chapter3.md b/nostarch/chapter3.md index 6ba6dd8..19581d4 100644 --- a/nostarch/chapter3.md +++ b/nostarch/chapter3.md @@ -878,7 +878,7 @@ The one difference is that in function signatures, we _must_ declare the type. T When you want a function to have multiple arguments, just separate them inside the function signature with commas, like this: ```text -fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) { +fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) { ``` And just like a `let` declaration with multiple patterns, a type must be applied to each pattern separately. To demonstrate, here’s a full example of a function with multiple arguments: @@ -956,7 +956,7 @@ Note that our bindings are called `a` and `b`, yet inside the function, we refer Functions can return values back to functions that call them. The signature for a function that returns a value looks like this: ```TEXT -fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) -> TYPE { +fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) -> TYPE { ``` In Rust, we don’t name return values, but we do declare their type, after the arrow (`->`). Here’s a sample program to illustrate this concept: diff --git a/src/ch03-03-functions.md b/src/ch03-03-functions.md index 756859c..0b27989 100644 --- a/src/ch03-03-functions.md +++ b/src/ch03-03-functions.md @@ -106,7 +106,7 @@ functions means that you almost never need them anywhere else. You can separate multiple arguments with a comma: ```text -fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) { +fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) { ``` Here’s a full example: @@ -168,7 +168,7 @@ passed as parameters don’t need to have the same name as the arguments. Functions can also return values back to the function that called them: ```TEXT -fn NAME(PATTERN, PATTERN, PATTERN, PATTERN...) -> TYPE { +fn NAME(PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE, PATTERN: TYPE...) -> TYPE { ``` We don’t name return values, but we do declare their type, after an arrow: