aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Yasskin <[email protected]>2010-07-18 03:15:14 +0800
committerGraydon Hoare <[email protected]>2010-07-18 14:25:18 +0800
commitbd56de745b64d6d3eb8b64f9716ca08811a6fd72 (patch)
treeabac46f4e74d2848ce888e05e926968e526603cf
parentWork around auto-dereference crash in rustboot. (diff)
downloadrust-bd56de745b64d6d3eb8b64f9716ca08811a6fd72.tar.xz
rust-bd56de745b64d6d3eb8b64f9716ca08811a6fd72.zip
Explain that rust methods can't call other methods on the same object, either
implicitly or explicitly.
-rw-r--r--doc/rust.texi44
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/rust.texi b/doc/rust.texi
index 0b6f0cae..1f780d6f 100644
--- a/doc/rust.texi
+++ b/doc/rust.texi
@@ -1811,6 +1811,50 @@ c.incr();
check (c.get() == 3);
@end example
+There is no @emph{this} or @emph{self} available inside an object's
+methods, either implicitly or explicitly, so you can't directly call
+other methods. For example:
+@example
+obj my_obj() @{
+ fn get() -> int @{
+ ret 3;
+ @}
+ fn foo() @{
+ auto c = get(); // Fails
+ @}
+@}
+@end example
+
+The current replacement is to write a factory function for your type,
+which provides any private helper functions:
+@example
+type my_obj =
+ obj @{
+ fn get() -> int;
+ fn foo();
+ @};
+
+fn mk_my_obj() -> my_obj @{
+ fn get_helper() -> int @{
+ ret 3;
+ @}
+
+ obj impl() @{
+ fn get() -> int @{
+ ret get_helper();
+ @}
+ fn foo() @{
+ auto c = get_helper(); // Works
+ @}
+ @}
+
+ ret impl();
+@}
+@end example
+
+This factory function also allows you to bind the object's state
+variables to initial values.
+
@node Ref.Item.Type
@subsection Ref.Item.Type
@c * Ref.Item.Type:: Items defining the types of values and slots.