about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBenjamin Herr <ben@0x539.de>2013-03-02 01:07:01 +0100
committerBenjamin Herr <ben@0x539.de>2013-03-02 01:07:01 +0100
commit382143abd871d9b2c73df08ffd2928c44f314ab3 (patch)
treec531788e4dd219aac9546cdec8eb2103d0f7e331
parentcab8ec242bc34dceb8aded6ec71ddf17e5966d86 (diff)
downloadrust-382143abd871d9b2c73df08ffd2928c44f314ab3.tar.gz
rust-382143abd871d9b2c73df08ffd2928c44f314ab3.zip
doc/rust.md: Demonstrate the `f::<T>()` syntax more often
The "Generic functions" subsection mentions that generic functions are
instantiated based on context, so let's also mention right away (with a
link to the #paths section) that an explicit form is available.

This also adds an example to the function call expression section that
explicitly instantiates a generic function.
-rw-r--r--doc/rust.md9
1 files changed, 8 insertions, 1 deletions
diff --git a/doc/rust.md b/doc/rust.md
index 13d897a00d2..862358859e5 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -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
@@ -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