Skip to content

Instantly share code, notes, and snippets.

@jld
Last active December 14, 2015 03:29
Show Gist options
  • Select an option

  • Save jld/5021325 to your computer and use it in GitHub Desktop.

Select an option

Save jld/5021325 to your computer and use it in GitHub Desktop.
Rust has a bad day with side-effects.
struct S { x: int, y: int }
fn effect(s: &str) -> S { io::println(s); S { x: 0, y: 0 } }
pub fn main() {
let _foo = S { x: 1, .. effect("this will be printed") };
let _ = S { x: 2, .. effect("and this won't") };
let _ = S { x: effect("but this will").y, .. effect("(still no)") };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment