22
33Index:
44- [ docs] ( #docs-module )
5+ - [ trait] ( #trait-module )
56- [ array] ( #array-module )
67- [ list] ( #list-module )
78- [ math] ( #math-module )
@@ -53,6 +54,89 @@ The interface for a documentation generator.
5354
5455Create an object to document members of a module.
5556
57+ ## trait module
58+
59+
60+ A trait is a reusable set of methods that can be used to extend the behavior of
61+ a type. It's an interface that defines a contract that must be implemented by
62+ any type that wishes to support the trait. Any objects that implement the trait
63+ can be converted to a _ trait object_ , which can be used to call the methods
64+ defined by the trait.
65+
66+ For example, you can define a ` Printable ` trait with a method ` print() ` :
67+ ``` c++
68+ let Printable = trait::new (" Printable" , [trait::method(" print" )]);
69+
70+ trait::impl (Printable, MyType, struct {
71+ function print(self) {
72+ println("MyType ", self.value);
73+ }
74+ });
75+
76+ # Both equivalent:
77+ Printable.print(MyType { value = 42 });
78+ trait::cast(Printable, MyType { value = 42 }).print();
79+ ```
80+
81+
82+ ### function `implements(obj, trait)`
83+
84+ Check if an object implements a trait.
85+
86+ If `obj` is a trait object, `implements` will return true if its trait is
87+ `trait`. Otherwise return true if `obj` implements the trait and could be cast
88+ to a trait object for `trait`.
89+
90+ ### function `downcast(traitobject)`
91+
92+ Retrieve the underlying object from a trait object.
93+
94+ ### function `impl(trait, type, implementation)`
95+
96+ Implement a trait for some type.
97+
98+ The `implementation` should be a struct containing methods for each method
99+ defined in the trait. For example:
100+
101+ ```c++
102+ trait::impl(ToString, MyType, struct {
103+ function to_string(self) {
104+ # ...
105+ }
106+ });
107+ ```
108+
109+ ### function ` primitive(typename) `
110+
111+ Used to specify a primitive type like ` "string" ` as the implementor of a trait. Example:
112+
113+ ``` c++
114+ trait::impl (ToString, trait::primitive("string"), struct {
115+ function to_string(self) {
116+ return self;
117+ }
118+ });
119+ ```
120+
121+
122+ ### function `cast(trait, obj)`
123+
124+ Create a trait object for the given trait and object.
125+
126+ `obj` must be an object that implements the trait. Any trait methods can be
127+ called directly on the trait object.
128+
129+ ### function `new(name, methods)`
130+
131+ Create a new trait with the given name and methods.
132+
133+ Any implementors must define all methods, though the signature of the methods is
134+ not checked.
135+
136+ ### function `method(name)`
137+
138+ Create a trait method declaration for use with `trait::new()`
139+
56140## array module
57141
58142Functions for working with arrays.
@@ -112,10 +196,6 @@ Find the index of the element for which `predicate` returns true. If there is no
112196
113197A collector for converting an iterator into an array.
114198
115- ### function ` iter(array) `
116-
117- Create an iterator from array ` array ` .
118-
119199### function `length(array)`
120200
121201Get the length of array `array`.
@@ -184,10 +264,6 @@ Insert `value` at the front of `list`
184264
185265Get the length of the list.
186266
187- ### function ` iter(list) `
188-
189- Create an iterator over ` list ` .
190-
191267### function `new()`
192268
193269Create a new, empty linked list.
@@ -393,9 +469,37 @@ Create an iterator that counts from 0 to `to`.
393469
394470Create an iterator that counts up from `n` indefinitely.
395471
396- ### struct ` collector `
472+ ### method `finalize()`
473+
474+ Finalizes the collection by returning the reduced result.
475+
476+ ### method `reduce()`
477+
478+ Reduces the iterator into the collection by adding an item.
479+
480+ ### method `init()`
481+
482+ Initializes the collection for reduction.
483+
484+ ### trait `Collector`
485+
486+ A trait for converting an iterator into an arbitrary collection.
487+
488+ ### method `next()`
489+
490+ Returns the next value in the sequence, or STOP if there are no more values.
491+
492+ ### trait `Iterator`
493+
494+ A trait for objects that can produce a sequence of values.
397495
398- An struct defining the required functions to convert an iterator into an arbitrary collection.
496+ ### method `iter()`
497+
498+ Returns an iterator for the object.
499+
500+ ### trait `Iterable`
501+
502+ A trait for objects that can be iterated over.
399503
400504### object `STOP`
401505
@@ -476,10 +580,6 @@ Create an empty arraylist with default initial capacity.
476580
477581Create an empty arraylist with the given initial capacity.
478582
479- ### function ` iter(list) `
480-
481- Create an iterator over arraylist ` list ` .
482-
483583### function `from_array(len, array)`
484584
485585Create a new arraylist from `array`. The `len` argument should be the length
@@ -518,10 +618,6 @@ Set the value of `key` in `list` to `value`.
518618A collector for converting an iterator of
519619entries into an assoclist.
520620
521- ### function ` iter(list) `
522-
523- Create an iterator over the entries of ` list ` .
524-
525621### function `length`
526622
527623Check the number of items in the list.
@@ -534,10 +630,6 @@ Create an empty assoclist.
534630
535631A compact byte array type.
536632
537- ### function ` iter(bytes) `
538-
539- Create an iterator over ` bytes ` .
540-
541633### object `collector`
542634
543635A collector for converting an iterator into byte array.
@@ -711,10 +803,6 @@ Parse `str` as an integer of base `base`. Currently only works for base 10.
711803A collector to convert an iterator of characters
712804or strings into a string.
713805
714- ### function ` iter(str) `
715-
716- Create an iterator over the characters in ` str ` .
717-
718806### function `from_bytes(bytes)`
719807
720808Convert a byte array to a string.
@@ -884,10 +972,6 @@ Get an iterator over the keys in `map`.
884972
885973Return the number of values in `map`.
886974
887- ### function ` iter(map) `
888-
889- Get an iterator over the key-value pairs in ` map ` .
890-
891975### function `entries(map)`
892976
893977Get an iterator over the key-value pairs in `map`.
0 commit comments