@@ -51,7 +51,7 @@ struct AsciiArt
51
51
width : uint ,
52
52
height : uint ,
53
53
priv fill : char ,
54
- priv lines : ~[ ~[ mut char ] ] ,
54
+ priv lines : ~[ ~[ char ] ] ,
55
55
56
56
// This struct can be quite large so we'll disable copying: developers need
57
57
// to either pass these structs around via borrowed pointers or move them.
@@ -65,14 +65,14 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt
65
65
{
66
66
// Use an anonymous function to build a vector of vectors containing
67
67
// blank characters for each position in our canvas.
68
- let lines = do vec:: build_sized ( height)
68
+ let mut lines = do vec:: build_sized ( height)
69
69
|push|
70
70
{
71
71
for height . times
72
72
{
73
73
let mut line = ~[ ] ;
74
74
vec : : grow_set( & mut line, width-1 , & '.' , '.' ) ;
75
- push( vec :: cast_to_mut ( line) ) ;
75
+ push( line) ;
76
76
}
77
77
} ;
78
78
@@ -84,7 +84,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt
84
84
// Methods particular to the AsciiArt struct.
85
85
impl AsciiArt
86
86
{
87
- fn add_pt( x: int, y: int)
87
+ fn add_pt( & mut self , x: int, y: int)
88
88
{
89
89
if x >= 0 && x < self . width as int
90
90
{
@@ -99,7 +99,7 @@ impl AsciiArt
99
99
// element is:
100
100
// 1) potentially large
101
101
// 2) needs to be modified
102
- let row = & self . lines [ v] ;
102
+ let row = & mut self . lines [ v] ;
103
103
row[ h] = self . fill ;
104
104
}
105
105
}
@@ -125,12 +125,12 @@ impl AsciiArt : ToStr
125
125
#[ allow( default_methods) ]
126
126
trait Canvas
127
127
{
128
- fn add_point ( shape : Point ) ;
129
- fn add_rect ( shape : Rect ) ;
128
+ fn add_point ( & mut self , shape : Point ) ;
129
+ fn add_rect ( & mut self , shape : Rect ) ;
130
130
131
131
// Unlike interfaces traits support default implementations.
132
132
// Got an ICE as soon as I added this method.
133
- fn add_points ( shapes : & [ Point ] )
133
+ fn add_points ( & mut self , shapes : & [ Point ] )
134
134
{
135
135
for shapes. each |pt| { self . add_point ( * pt) } ;
136
136
}
@@ -141,12 +141,12 @@ trait Canvas
141
141
// and code can use them polymorphically via the Canvas trait.
142
142
impl AsciiArt : Canvas
143
143
{
144
- fn add_point ( shape : Point )
144
+ fn add_point ( & mut self , shape : Point )
145
145
{
146
146
self . add_pt ( shape. x , shape. y ) ;
147
147
}
148
148
149
- fn add_rect ( shape : Rect )
149
+ fn add_rect ( & mut self , shape : Rect )
150
150
{
151
151
// Add the top and bottom lines.
152
152
for int:: range( shape. top_left. x, shape. top_left. x + shape. size. width)
@@ -188,7 +188,7 @@ fn test_ascii_art_ctor()
188
188
189
189
fn test_add_pt ( )
190
190
{
191
- let art = AsciiArt ( 3 , 3 , '*' ) ;
191
+ let mut art = AsciiArt ( 3 , 3 , '*' ) ;
192
192
art. add_pt ( 0 , 0 ) ;
193
193
art. add_pt ( 0 , -10 ) ;
194
194
art. add_pt ( 1 , 2 ) ;
@@ -198,7 +198,7 @@ fn test_add_pt()
198
198
199
199
fn test_shapes ( )
200
200
{
201
- let art = AsciiArt ( 4 , 4 , '*' ) ;
201
+ let mut art = AsciiArt ( 4 , 4 , '*' ) ;
202
202
art. add_rect ( Rect { top_left : Point { x : 0 , y : 0 } , size : Size { width : 4 , height : 4 } } ) ;
203
203
art. add_point ( Point { x : 2 , y : 2 } ) ;
204
204
assert check_strs( art. to_str ( ) , "****\n *..*\n *.**\n ****" ) ;
0 commit comments