Skip to content

Commit 05d06b5

Browse files
committed
---
yaml --- r: 4545 b: refs/heads/master c: d2c1fbd h: refs/heads/master i: 4543: 6739e16 v: v3
1 parent 1791211 commit 05d06b5

File tree

2 files changed

+22
-38
lines changed

2 files changed

+22
-38
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ba7c8f18d4d18e519649386fb558480af7e4f033
2+
refs/heads/master: d2c1fbd218e305310c1774d2d5fa8557a74ab842

trunk/doc/rust.texi

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ the large'', that is, of creating and maintaining @emph{boundaries} -- both
127127
abstract and operational -- that preserve large-system @emph{integrity},
128128
@emph{availability} and @emph{concurrency}.
129129

130-
It supports a mixture of imperative procedural, concurrent actor, object
131-
oriented and pure functional styles. Rust also supports generic programming
132-
and metaprogramming, in both static and dynamic styles.
130+
It supports a mixture of imperative procedural, concurrent actor,
131+
object-oriented and pure functional styles. Rust also supports generic
132+
programming and metaprogramming, in both static and dynamic styles.
133133

134134
@menu
135135
* Goals:: Intentions, motivations.
@@ -1894,52 +1894,28 @@ let c: counter = counter(1);
18941894
18951895
c.incr();
18961896
c.incr();
1897-
assert (c.get() == 3);
1897+
assert c.get() == 3;
18981898
@end example
18991899

1900-
There is no @emph{this} or @emph{self} available inside an object's
1901-
methods, either implicitly or explicitly, so you can't directly call
1902-
other methods. For example:
1900+
Inside an object's methods, you can make @emph{self-calls} using the
1901+
@code{self} keyword.
19031902
@example
19041903
obj my_obj() @{
19051904
fn get() -> int @{
19061905
ret 3;
19071906
@}
1908-
fn foo() @{
1909-
let c = get(); // Fails
1907+
fn foo() -> int @{
1908+
let c = self.get();
1909+
ret c + 2;
19101910
@}
19111911
@}
1912-
@end example
19131912
1914-
The current replacement is to write a factory function for your type,
1915-
which provides any private helper functions:
1916-
@example
1917-
type my_obj =
1918-
obj @{
1919-
fn get() -> int;
1920-
fn foo();
1921-
@};
1922-
1923-
fn mk_my_obj() -> my_obj @{
1924-
fn get_helper() -> int @{
1925-
ret 3;
1926-
@}
1927-
1928-
obj impl() @{
1929-
fn get() -> int @{
1930-
ret get_helper();
1931-
@}
1932-
fn foo() @{
1933-
let c = get_helper(); // Works
1934-
@}
1935-
@}
1936-
1937-
ret impl();
1938-
@}
1913+
let o = my_obj();
1914+
assert o.foo() == 5;
19391915
@end example
19401916

1941-
This factory function also allows you to bind the object's state
1942-
variables to initial values.
1917+
Rust objects are extendable with additional methods and fields using
1918+
@emph{anonymous object} expressions. @xref{Ref.Expr.AnonObj}.
19431919

19441920
@node Ref.Item.Type
19451921
@subsection Ref.Item.Type
@@ -2911,6 +2887,7 @@ effects of the expression's evaluation.
29112887
* Ref.Expr.Claim:: Expression for static (unsafe) or dynamic assertion of typestate.
29122888
* Ref.Expr.Assert:: Expression for halting the program if a boolean condition fails to hold.
29132889
* Ref.Expr.IfCheck:: Expression for dynamic testing of typestate.
2890+
* Ref.Expr.AnonObj:: Expression for extending objects with additional methods.
29142891
@end menu
29152892

29162893

@@ -3632,6 +3609,13 @@ the condition may be any boolean-typed expression, and the compiler makes no
36323609
use of the knowledge that the condition holds if the program continues to
36333610
execute after the @code{assert}.
36343611

3612+
@node Ref.Expr.AnonObj
3613+
@subsection Ref.Expr.AnonObj
3614+
@c * Ref.Expr.AnonObj:: Expression that extends an object with additional methods.
3615+
@cindex Anonymous objects
3616+
3617+
An @emph{anonymous object} expression extends an existing object with methods.
3618+
36353619
@page
36363620
@node Ref.Run
36373621
@section Ref.Run

0 commit comments

Comments
 (0)