File: rustc-exterior.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,245,360 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (41 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[cfg(feature = "use_core")]
extern crate core;

use std::cell::Cell;

#[macro_use]
extern crate derivative;

#[derive(Derivative)]
#[derivative(Copy, Clone)]
struct Point {x: isize, y: isize, z: isize}

fn f(p: &Cell<Point>) {
    assert_eq!(p.get().z, 12);
    p.set(Point {x: 10, y: 11, z: 13});
    assert_eq!(p.get().z, 13);
}

#[test]
fn main() {
    let a: Point = Point {x: 10, y: 11, z: 12};
    let b: &Cell<Point> = &Cell::new(a);
    assert_eq!(b.get().z, 12);
    f(b);
    assert_eq!(a.x, 10);
    assert_eq!(a.y, 11);
    assert_eq!(a.z, 12);
    assert_eq!(b.get().x, 10);
    assert_eq!(b.get().y, 11);
    assert_eq!(b.get().z, 13);
}