Skip to content

Commit afd6196

Browse files
committed
auto merge of #5233 : bstrie/rust/deimpselfcore, r=graydon
2 parents 5f55a07 + 9db61e0 commit afd6196

File tree

19 files changed

+338
-315
lines changed

19 files changed

+338
-315
lines changed

src/libcore/cell.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub pure fn empty_cell<T>() -> Cell<T> {
3030

3131
pub impl<T> Cell<T> {
3232
/// Yields the value, failing if the cell is empty.
33-
fn take() -> T {
33+
fn take(&self) -> T {
3434
if self.is_empty() {
3535
fail!(~"attempt to take an empty cell");
3636
}
@@ -41,20 +41,20 @@ pub impl<T> Cell<T> {
4141
}
4242
4343
/// Returns the value, failing if the cell is full.
44-
fn put_back(value: T) {
44+
fn put_back(&self, value: T) {
4545
if !self.is_empty() {
4646
fail!(~"attempt to put a value back into a full cell");
4747
}
4848
self.value = Some(value);
4949
}
5050

5151
/// Returns true if the cell is empty and false if the cell is full.
52-
pure fn is_empty() -> bool {
52+
pure fn is_empty(&self) -> bool {
5353
self.value.is_none()
5454
}
5555

5656
// Calls a closure with a reference to the value.
57-
fn with_ref<R>(op: fn(v: &T) -> R) -> R {
57+
fn with_ref<R>(&self, op: fn(v: &T) -> R) -> R {
5858
let v = self.take();
5959
let r = op(&v);
6060
self.put_back(v);

src/libcore/comm.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ pub use pipes::Selectable;
2424
/// A trait for things that can send multiple messages.
2525
pub trait GenericChan<T> {
2626
/// Sends a message.
27-
fn send(x: T);
27+
fn send(&self, x: T);
2828
}
2929

3030
/// Things that can send multiple messages and can detect when the receiver
3131
/// is closed
3232
pub trait GenericSmartChan<T> {
3333
/// Sends a message, or report if the receiver has closed the connection.
34-
fn try_send(x: T) -> bool;
34+
fn try_send(&self, x: T) -> bool;
3535
}
3636

3737
/// A trait for things that can receive multiple messages.
3838
pub trait GenericPort<T> {
3939
/// Receives a message, or fails if the connection closes.
40-
fn recv() -> T;
40+
fn recv(&self) -> T;
4141

4242
/** Receives a message, or returns `none` if
4343
the connection is closed or closes.
4444
*/
45-
fn try_recv() -> Option<T>;
45+
fn try_recv(&self) -> Option<T>;
4646
}
4747

4848
/// Ports that can `peek`
4949
pub trait Peekable<T> {
5050
/// Returns true if a message is available
51-
pure fn peek() -> bool;
51+
pure fn peek(&self) -> bool;
5252
}
5353

5454
/// Returns the index of an endpoint that is ready to receive.
@@ -105,7 +105,7 @@ pub fn stream<T:Owned>() -> (Port<T>, Chan<T>) {
105105
}
106106
107107
impl<T: Owned> GenericChan<T> for Chan<T> {
108-
fn send(x: T) {
108+
fn send(&self, x: T) {
109109
let mut endp = None;
110110
endp <-> self.endp;
111111
self.endp = Some(
@@ -115,7 +115,7 @@ impl<T: Owned> GenericChan<T> for Chan<T> {
115115
116116
impl<T: Owned> GenericSmartChan<T> for Chan<T> {
117117
118-
fn try_send(x: T) -> bool {
118+
fn try_send(&self, x: T) -> bool {
119119
let mut endp = None;
120120
endp <-> self.endp;
121121
match streamp::client::try_data(unwrap(endp), x) {
@@ -129,15 +129,15 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
129129
}
130130
131131
impl<T: Owned> GenericPort<T> for Port<T> {
132-
fn recv() -> T {
132+
fn recv(&self) -> T {
133133
let mut endp = None;
134134
endp <-> self.endp;
135135
let streamp::data(x, endp) = recv(unwrap(endp));
136136
self.endp = Some(endp);
137137
x
138138
}
139139
140-
fn try_recv() -> Option<T> {
140+
fn try_recv(&self) -> Option<T> {
141141
let mut endp = None;
142142
endp <-> self.endp;
143143
match try_recv(unwrap(endp)) {
@@ -151,7 +151,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
151151
}
152152
153153
impl<T: Owned> Peekable<T> for Port<T> {
154-
pure fn peek() -> bool {
154+
pure fn peek(&self) -> bool {
155155
unsafe {
156156
let mut endp = None;
157157
endp <-> self.endp;
@@ -166,7 +166,7 @@ impl<T: Owned> Peekable<T> for Port<T> {
166166
}
167167
168168
impl<T: Owned> Selectable for Port<T> {
169-
pure fn header() -> *PacketHeader {
169+
pure fn header(&self) -> *PacketHeader {
170170
unsafe {
171171
match self.endp {
172172
Some(ref endp) => endp.header(),
@@ -189,11 +189,11 @@ pub fn PortSet<T: Owned>() -> PortSet<T>{
189189
190190
pub impl<T: Owned> PortSet<T> {
191191
192-
fn add(port: Port<T>) {
192+
fn add(&self, port: Port<T>) {
193193
self.ports.push(port)
194194
}
195195
196-
fn chan() -> Chan<T> {
196+
fn chan(&self) -> Chan<T> {
197197
let (po, ch) = stream();
198198
self.add(po);
199199
ch
@@ -202,7 +202,7 @@ pub impl<T: Owned> PortSet<T> {
202202
203203
impl<T: Owned> GenericPort<T> for PortSet<T> {
204204
205-
fn try_recv() -> Option<T> {
205+
fn try_recv(&self) -> Option<T> {
206206
let mut result = None;
207207
// we have to swap the ports array so we aren't borrowing
208208
// aliasable mutable memory.
@@ -224,14 +224,14 @@ impl<T: Owned> GenericPort<T> for PortSet<T> {
224224
result
225225
}
226226
227-
fn recv() -> T {
227+
fn recv(&self) -> T {
228228
self.try_recv().expect("port_set: endpoints closed")
229229
}
230230
231231
}
232232
233233
impl<T: Owned> Peekable<T> for PortSet<T> {
234-
pure fn peek() -> bool {
234+
pure fn peek(&self) -> bool {
235235
// It'd be nice to use self.port.each, but that version isn't
236236
// pure.
237237
for vec::each(self.ports) |p| {
@@ -245,7 +245,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
245245
pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
246246
247247
impl<T: Owned> GenericChan<T> for SharedChan<T> {
248-
fn send(x: T) {
248+
fn send(&self, x: T) {
249249
let mut xx = Some(x);
250250
do self.with_imm |chan| {
251251
let mut x = None;
@@ -256,7 +256,7 @@ impl<T: Owned> GenericChan<T> for SharedChan<T> {
256256
}
257257
258258
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
259-
fn try_send(x: T) -> bool {
259+
fn try_send(&self, x: T) -> bool {
260260
let mut xx = Some(x);
261261
do self.with_imm |chan| {
262262
let mut x = None;
@@ -274,27 +274,27 @@ pub fn SharedChan<T:Owned>(c: Chan<T>) -> SharedChan<T> {
274274
/// Receive a message from one of two endpoints.
275275
pub trait Select2<T: Owned, U: Owned> {
276276
/// Receive a message or return `None` if a connection closes.
277-
fn try_select() -> Either<Option<T>, Option<U>>;
277+
fn try_select(&self) -> Either<Option<T>, Option<U>>;
278278
/// Receive a message or fail if a connection closes.
279-
fn select() -> Either<T, U>;
279+
fn select(&self) -> Either<T, U>;
280280
}
281281
282282
impl<T: Owned, U: Owned,
283283
Left: Selectable + GenericPort<T>,
284284
Right: Selectable + GenericPort<U>>
285285
Select2<T, U> for (Left, Right) {
286286
287-
fn select() -> Either<T, U> {
288-
match self {
287+
fn select(&self) -> Either<T, U> {
288+
match *self {
289289
(ref lp, ref rp) => match select2i(lp, rp) {
290290
Left(()) => Left (lp.recv()),
291291
Right(()) => Right(rp.recv())
292292
}
293293
}
294294
}
295295
296-
fn try_select() -> Either<Option<T>, Option<U>> {
297-
match self {
296+
fn try_select(&self) -> Either<Option<T>, Option<U>> {
297+
match *self {
298298
(ref lp, ref rp) => match select2i(lp, rp) {
299299
Left(()) => Left (lp.try_recv()),
300300
Right(()) => Right(rp.try_recv())

src/libcore/condition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ pub impl<T, U> Condition<T, U> {
3535
}
3636
}
3737

38-
fn raise(t: T) -> U {
38+
fn raise(&self, t: T) -> U {
3939
let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
4040
self.raise_default(t, || fail!(copy msg))
4141
}
4242

43-
fn raise_default(t: T, default: &fn() -> U) -> U {
43+
fn raise_default(&self, t: T, default: &fn() -> U) -> U {
4444
unsafe {
4545
match local_data_pop(self.key) {
4646
None => {

src/libcore/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ priv impl<T> DList<T> {
148148
fail!(~"That node isn't on this dlist.")
149149
}
150150
}
151-
fn make_mine(nobe: @mut DListNode<T>) {
151+
fn make_mine(&self, nobe: @mut DListNode<T>) {
152152
if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked {
153153
fail!(~"Cannot insert node that's already on a dlist!")
154154
}

0 commit comments

Comments
 (0)