Update docs for import/export
This commit is contained in:
parent
0d83956e2b
commit
556de425b3
@ -1757,12 +1757,19 @@ path required to refer to a module item.
|
||||
dependencies are independently declared with @code{use}
|
||||
declarations. @xref{Ref.Comp.Crate}.
|
||||
|
||||
An example of an import:
|
||||
An example of imports:
|
||||
@example
|
||||
import std::math::sin;
|
||||
import std::option::*;
|
||||
import std::str::@{char_at, hash@};
|
||||
|
||||
fn main() @{
|
||||
// Equivalent to 'log std::math::sin(1.0);'
|
||||
log sin(1.0);
|
||||
// Equivalent to 'log std::option::some(1.0);'
|
||||
log some(1.0);
|
||||
// Equivalent to 'log std::str::hash(std::str::char_at("foo"));'
|
||||
log hash(char_at("foo"));
|
||||
@}
|
||||
@end example
|
||||
|
||||
@ -1800,6 +1807,27 @@ fn main() @{
|
||||
@}
|
||||
@end example
|
||||
|
||||
Multiple items may be exported from a single export declaration:
|
||||
|
||||
@example
|
||||
mod foo @{
|
||||
export primary, secondary;
|
||||
|
||||
fn primary() @{
|
||||
helper(1, 2);
|
||||
helper(3, 4);
|
||||
@}
|
||||
|
||||
fn secondary() @{
|
||||
@dots{}
|
||||
@}
|
||||
|
||||
fn helper(x: int, y: int) @{
|
||||
@dots{}
|
||||
@}
|
||||
@}
|
||||
@end example
|
||||
|
||||
|
||||
@node Ref.Item.Fn
|
||||
@subsection Ref.Item.Fn
|
||||
|
Loading…
Reference in New Issue
Block a user