Skip to content

Commit f212543

Browse files
author
Olivier Saut
committed
Remove the get function
Rust is now preferring methods over functions and there is no legacy with ARC
1 parent b5ab101 commit f212543

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

src/libextra/arc.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub impl<'self> Condvar<'self> {
107107
****************************************************************************/
108108

109109
/// An atomically reference counted wrapper for shared immutable state.
110-
struct ARC<T> { x: UnsafeAtomicRcBox<T> }
110+
pub struct ARC<T> { x: UnsafeAtomicRcBox<T> }
111111

112112
/// Create an atomically reference counted wrapper.
113113
pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
@@ -118,12 +118,8 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
118118
* Access the underlying data in an atomically reference counted
119119
* wrapper.
120120
*/
121-
pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
122-
rc.get()
123-
}
124-
125-
impl<T:Const+Owned> ARC<T> {
126-
pub fn get<'a>(&'a self) -> &'a T {
121+
pub impl<T:Const+Owned> ARC<T> {
122+
fn get<'a>(&'a self) -> &'a T {
127123
unsafe { &*self.x.get_immut() }
128124
}
129125
}
@@ -512,34 +508,31 @@ pub impl<'self, T:Const + Owned> RWReadMode<'self, T> {
512508
#[cfg(test)]
513509
mod tests {
514510
use core::prelude::*;
515-
511+
use core::cell::Cell;
516512
use arc::*;
517513
use arc;
518514

519-
use core::cell::Cell;
520-
use core::task;
521-
522515
#[test]
523516
fn manually_share_arc() {
524517
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
525-
let arc_v = arc::ARC(v);
518+
let arc_v = ARC(v);
526519

527520
let (p, c) = comm::stream();
528521

529522
do task::spawn() || {
530523
let p = comm::PortSet::new();
531524
c.send(p.chan());
532525

533-
let arc_v = p.recv();
526+
let arc_v : ARC<~[int]> = p.recv();
534527

535-
let v = copy *arc::get::<~[int]>(&arc_v);
528+
let v = copy (*arc_v.get());
536529
assert_eq!(v[3], 4);
537530
};
538531

539532
let c = p.recv();
540-
c.send(arc::clone(&arc_v));
533+
c.send(arc_v.clone());
541534

542-
assert_eq!((*arc::get(&arc_v))[2], 3);
535+
assert_eq!(arc_v.get()[2], 3);
543536
assert_eq!(arc_v.get()[4], 5);
544537

545538
info!(arc_v);

src/test/bench/graph500-bfs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// xfail-pretty
22

3-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
3+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
44
// file at the top-level directory of this distribution and at
55
// http://rust-lang.org/COPYRIGHT.
66
//
@@ -234,7 +234,7 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
234234
black(node_id)
235235
};
236236

237-
let graph_vec = arc::get(graph); // FIXME #3387 requires this temp
237+
let graph_vec = graph.get(); // FIXME #3387 requires this temp
238238
let mut colors = do vec::from_fn(graph_vec.len()) |i| {
239239
if i as node_id == key {
240240
gray(key)
@@ -266,13 +266,13 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
266266

267267
let color = arc::ARC(colors);
268268

269-
let color_vec = arc::get(&color); // FIXME #3387 requires this temp
269+
let color_vec = color.get(); // FIXME #3387 requires this temp
270270
colors = do par::mapi(*color_vec) {
271-
let colors = arc::clone(&color);
272-
let graph = arc::clone(graph);
271+
let colors = color.clone();
272+
let graph = graph.clone();
273273
let result: ~fn(x: uint, y: &color) -> color = |i, c| {
274-
let colors = arc::get(&colors);
275-
let graph = arc::get(&graph);
274+
let colors = colors.get();
275+
let graph = graph.get();
276276
match *c {
277277
white => {
278278
let i = i as node_id;

src/test/compile-fail/no-capture-arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -18,11 +18,11 @@ fn main() {
1818
let arc_v = arc::ARC(v);
1919

2020
do task::spawn() {
21-
let v = *arc::get(&arc_v);
21+
let v = arc_v.get();
2222
assert_eq!(v[3], 4);
2323
};
2424

25-
assert_eq!((*arc::get(&arc_v))[2], 3);
25+
assert_eq!((arc_v.get())[2], 3);
2626

2727
info!(arc_v);
2828
}

src/test/compile-fail/no-reuse-move-arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -16,11 +16,11 @@ fn main() {
1616
let arc_v = arc::ARC(v);
1717

1818
do task::spawn() { //~ NOTE `arc_v` moved into closure environment here
19-
let v = *arc::get(&arc_v);
19+
let v = arc_v.get();
2020
assert_eq!(v[3], 4);
2121
};
2222

23-
assert!((*arc::get(&arc_v))[2] == 3); //~ ERROR use of moved value: `arc_v`
23+
assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v`
2424

2525
info!(arc_v);
2626
}

0 commit comments

Comments
 (0)