File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #[ derive( Debug ) ]
2+ struct User {
3+ username : String ,
4+ active : bool ,
5+ }
6+ impl User {
7+ fn new ( username : String ) -> User {
8+ User {
9+ username,
10+ active : true ,
11+ }
12+ }
13+ }
14+ impl User {
15+ fn clone ( & self , active : bool ) -> User {
16+ User {
17+ username : self . username . clone ( ) ,
18+ active : active,
19+ }
20+ }
21+ }
22+ pub fn basics ( ) {
23+ let strings = [ "" ; 10 ] ;
24+ println ! ( "Strings: {:?}" , strings) ;
25+
26+ let mut s = String :: from ( "value" ) ;
27+ let r1 = & s;
28+ let r2 = & s;
29+ println ! ( "r1: {}, r2: {}" , r1, r2) ;
30+ let r3 = & mut s;
31+ r3. push_str ( "-plus" ) ;
32+ println ! ( "r3: {}" , r3) ;
33+
34+ let mut user = User :: new ( String :: from ( "user1" ) ) . clone ( false ) ;
35+ println ! ( "user: {:#?}, active={}" , user, user. active) ;
36+ let name = user. username ;
37+ user. username = String :: from ( "user2" ) ;
38+ println ! ( "name: {}, user: {:?}" , name, user) ;
39+ }
Original file line number Diff line number Diff line change 11mod guessgame;
2+ mod basics;
23
34fn main ( ) {
5+ basics:: basics ( ) ;
6+ println ! ( ) ;
47 guessgame:: guess_game ( ) ;
58}
You can’t perform that action at this time.
0 commit comments