This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Service struct { | |
name string | |
namespace string | |
} | |
func main() { | |
svc1 := Service{ | |
name: "nginx", | |
namespace: "default", | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut signal = "kill".to_string(); | |
loop { | |
exit(signal); | |
signal = "kill".to_string(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo run | |
Compiling rust-ownership v0.1.0 (/home/isim/rust-ownership) | |
error[E0382]: use of moved value: `signal` | |
--> src/main.rs:4:14 | |
| | |
2 | let signal = "kill".to_string(); | |
| ------ move occurs because `signal` has type `String`, which does not implement the `Copy` trait | |
3 | loop { | |
4 | exit(signal) | |
| ^^^^^^ value moved here, in previous iteration of loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let signal = "kill".to_string(); | |
loop { | |
exit(signal); | |
} | |
} | |
fn exit(s: String) { | |
if s == "kill" { | |
println!("exiting with signal {}", s); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo run | |
Compiling rust-ownership v0.1.0 (/home/isim/rust-ownership) | |
error[E0382]: borrow of moved value: `s` | |
--> src/main.rs:26:9 | |
| | |
25 | let s = "some data".to_string(); | |
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait | |
26 | (s, s.len()) | |
| - ^^^^^^^ value borrowed here after move | |
| | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
b, n := read() | |
fmt.Printf("data: %s\nlen: %d\n", b, n) | |
} | |
func read() (string, int) { | |
s := "some data" | |
return s, len(s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo run -q | |
svc: nginx.defaultsvc.cluster.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let svc = "nginx.default".to_string(); | |
let strict = true; | |
if strict { | |
println!("svc: {}", fqdn(svc)); | |
} else { | |
println!("svc: {}", svc); | |
} | |
println!("svc: {}", svc); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
svc := "nginx.default" | |
strict := true | |
if strict { | |
fmt.Printf("%s\n", fqdn(svc)) | |
} else { | |
fmt.Printf("%s\n", svc) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cargo run | |
Compiling rust-ownership v0.1.0 (/home/isim/rust-ownership) | |
error[E0505]: cannot move out of `str` because it is borrowed | |
--> src/main.rs:3:62 | |
| | |
3 | println!("original: {}\nupdated: {}", str, append_suffix(str)); | |
| ---------------------------------------------------------^^^-- | |
| | | | | |
| | | move out of `str` occurs here | |
| | borrow of `str` occurs here |