The following intset program introduces Rust's
struct. It defines an IntSet type, a set of
integers that holds each value at most once, and stores the values in a
Vec<i32>.
The impl IntSet block shows three kinds of functions:
self
parameter and are called with ::. The constructor
IntSet::new() returns an empty set, and
IntSet::from_slice() builds a set from a slice.
&self methods may read the struct but
not change it: len, is_empty,
contains, union, and
intersection.
&mut self methods may change the
struct: insert, remove, and
clear. You can only call them on a variable declared with
let mut.
The #[derive(Debug)] attribute on the struct has the
compiler generate the code needed to print an IntSet with
the {:?} format, as in println!("{:?}", a).
This zip file contains the complete crate.