Skip to content

doc/rust.md: Demonstrate the f::<T>() syntax more often #5188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
with `int`, and require the closure parameter to have type
`fn(int)`.

The type parameters can also be explicitly supplied in a trailing
[path](#paths) component after the function name. This might be necessary
if there is not sufficient context to determine the type parameters. For
example, `sys::size_of::<u32>() == 4`.

Since a parameter type is opaque to the generic function, the set of
operations that can be performed on it is limited. Values of parameter
type can always be moved, but they can only be copied when the
Expand Down Expand Up @@ -2040,12 +2045,14 @@ an optional reference slot to serve as the function's output, bound to the
`lval` on the right hand side of the call. If the function eventually returns,
then the expression completes.

An example of a call expression:
Some examples of call expressions:

~~~~
# fn add(x: int, y: int) -> int { 0 }
# use core::from_str::FromStr::from_str;

let x: int = add(1, 2);
let pi = from_str::<f32>("3.14");
~~~~

### Lambda expressions
Expand Down