pub impl<T> Cell<T> {
/// Yields the value, failing if the cell is empty.
- fn take() -> T {
+ fn take(&self) -> T {
if self.is_empty() {
fail!(~"attempt to take an empty cell");
}
}
/// Returns the value, failing if the cell is full.
- fn put_back(value: T) {
+ fn put_back(&self, value: T) {
if !self.is_empty() {
fail!(~"attempt to put a value back into a full cell");
}
}
/// Returns true if the cell is empty and false if the cell is full.
- pure fn is_empty() -> bool {
+ pure fn is_empty(&self) -> bool {
self.value.is_none()
}
// Calls a closure with a reference to the value.
- fn with_ref<R>(op: fn(v: &T) -> R) -> R {
+ fn with_ref<R>(&self, op: fn(v: &T) -> R) -> R {
let v = self.take();
let r = op(&v);
self.put_back(v);
/// A trait for things that can send multiple messages.
pub trait GenericChan<T> {
/// Sends a message.
- fn send(x: T);
+ fn send(&self, x: T);
}
/// Things that can send multiple messages and can detect when the receiver
/// is closed
pub trait GenericSmartChan<T> {
/// Sends a message, or report if the receiver has closed the connection.
- fn try_send(x: T) -> bool;
+ fn try_send(&self, x: T) -> bool;
}
/// A trait for things that can receive multiple messages.
pub trait GenericPort<T> {
/// Receives a message, or fails if the connection closes.
- fn recv() -> T;
+ fn recv(&self) -> T;
/** Receives a message, or returns `none` if
the connection is closed or closes.
*/
- fn try_recv() -> Option<T>;
+ fn try_recv(&self) -> Option<T>;
}
/// Ports that can `peek`
pub trait Peekable<T> {
/// Returns true if a message is available
- pure fn peek() -> bool;
+ pure fn peek(&self) -> bool;
}
/// Returns the index of an endpoint that is ready to receive.
}
impl<T: Owned> GenericChan<T> for Chan<T> {
- fn send(x: T) {
+ fn send(&self, x: T) {
let mut endp = None;
endp <-> self.endp;
self.endp = Some(
impl<T: Owned> GenericSmartChan<T> for Chan<T> {
- fn try_send(x: T) -> bool {
+ fn try_send(&self, x: T) -> bool {
let mut endp = None;
endp <-> self.endp;
match streamp::client::try_data(unwrap(endp), x) {
}
impl<T: Owned> GenericPort<T> for Port<T> {
- fn recv() -> T {
+ fn recv(&self) -> T {
let mut endp = None;
endp <-> self.endp;
let streamp::data(x, endp) = recv(unwrap(endp));
x
}
- fn try_recv() -> Option<T> {
+ fn try_recv(&self) -> Option<T> {
let mut endp = None;
endp <-> self.endp;
match try_recv(unwrap(endp)) {
}
impl<T: Owned> Peekable<T> for Port<T> {
- pure fn peek() -> bool {
+ pure fn peek(&self) -> bool {
unsafe {
let mut endp = None;
endp <-> self.endp;
}
impl<T: Owned> Selectable for Port<T> {
- pure fn header() -> *PacketHeader {
+ pure fn header(&self) -> *PacketHeader {
unsafe {
match self.endp {
Some(ref endp) => endp.header(),
pub impl<T: Owned> PortSet<T> {
- fn add(port: Port<T>) {
+ fn add(&self, port: Port<T>) {
self.ports.push(port)
}
- fn chan() -> Chan<T> {
+ fn chan(&self) -> Chan<T> {
let (po, ch) = stream();
self.add(po);
ch
impl<T: Owned> GenericPort<T> for PortSet<T> {
- fn try_recv() -> Option<T> {
+ fn try_recv(&self) -> Option<T> {
let mut result = None;
// we have to swap the ports array so we aren't borrowing
// aliasable mutable memory.
result
}
- fn recv() -> T {
+ fn recv(&self) -> T {
self.try_recv().expect("port_set: endpoints closed")
}
}
impl<T: Owned> Peekable<T> for PortSet<T> {
- pure fn peek() -> bool {
+ pure fn peek(&self) -> bool {
// It'd be nice to use self.port.each, but that version isn't
// pure.
for vec::each(self.ports) |p| {
pub type SharedChan<T> = unstable::Exclusive<Chan<T>>;
impl<T: Owned> GenericChan<T> for SharedChan<T> {
- fn send(x: T) {
+ fn send(&self, x: T) {
let mut xx = Some(x);
do self.with_imm |chan| {
let mut x = None;
}
impl<T: Owned> GenericSmartChan<T> for SharedChan<T> {
- fn try_send(x: T) -> bool {
+ fn try_send(&self, x: T) -> bool {
let mut xx = Some(x);
do self.with_imm |chan| {
let mut x = None;
/// Receive a message from one of two endpoints.
pub trait Select2<T: Owned, U: Owned> {
/// Receive a message or return `None` if a connection closes.
- fn try_select() -> Either<Option<T>, Option<U>>;
+ fn try_select(&self) -> Either<Option<T>, Option<U>>;
/// Receive a message or fail if a connection closes.
- fn select() -> Either<T, U>;
+ fn select(&self) -> Either<T, U>;
}
impl<T: Owned, U: Owned,
Right: Selectable + GenericPort<U>>
Select2<T, U> for (Left, Right) {
- fn select() -> Either<T, U> {
- match self {
+ fn select(&self) -> Either<T, U> {
+ match *self {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.recv()),
Right(()) => Right(rp.recv())
}
}
- fn try_select() -> Either<Option<T>, Option<U>> {
- match self {
+ fn try_select(&self) -> Either<Option<T>, Option<U>> {
+ match *self {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.try_recv()),
Right(()) => Right(rp.try_recv())
}
}
- fn raise(t: T) -> U {
+ fn raise(&self, t: T) -> U {
let msg = fmt!("Unhandled condition: %s: %?", self.name, t);
self.raise_default(t, || fail!(copy msg))
}
- fn raise_default(t: T, default: &fn() -> U) -> U {
+ fn raise_default(&self, t: T, default: &fn() -> U) -> U {
unsafe {
match local_data_pop(self.key) {
None => {
fail!(~"That node isn't on this dlist.")
}
}
- fn make_mine(nobe: @mut DListNode<T>) {
+ fn make_mine(&self, nobe: @mut DListNode<T>) {
if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked {
fail!(~"Cannot insert node that's already on a dlist!")
}
priv impl<A> DVec<A> {
#[inline(always)]
- pure fn check_not_borrowed() {
+ pure fn check_not_borrowed(&self) {
unsafe {
let data: *() = cast::reinterpret_cast(&self.data);
if data.is_null() {
}
#[inline(always)]
- fn give_back(data: ~[A]) {
+ fn give_back(&self, data: ~[A]) {
unsafe {
self.data = data;
}
}
/// Reserves space for N elements
- fn reserve(count: uint) {
+ fn reserve(&self, count: uint) {
vec::reserve(&mut self.data, count)
}
* and return a new vector to replace it with.
*/
#[inline(always)]
- fn swap(f: &fn(v: ~[A]) -> ~[A]) {
+ fn swap(&self, f: &fn(v: ~[A]) -> ~[A]) {
self.check_out(|v| self.give_back(f(v)))
}
/// Returns the number of elements currently in the dvec
#[inline(always)]
- pure fn len() -> uint {
+ pure fn len(&self) -> uint {
self.check_not_borrowed();
return self.data.len();
}
/// Overwrite the current contents
#[inline(always)]
- fn set(w: ~[A]) {
+ fn set(&self, w: ~[A]) {
self.check_not_borrowed();
self.data = w;
}
/// Remove and return the last element
- fn pop() -> A {
+ fn pop(&self) -> A {
do self.check_out |v| {
let mut v = v;
let result = v.pop();
}
/// Insert a single item at the front of the list
- fn unshift(t: A) {
+ fn unshift(&self, t: A) {
unsafe {
let mut data = cast::reinterpret_cast(&null::<()>());
data <-> self.data;
/// Append a single item to the end of the list
#[inline(always)]
- fn push(t: A) {
+ fn push(&self, t: A) {
self.check_not_borrowed();
self.data.push(t);
}
/// Remove and return the first element
- fn shift() -> A {
+ fn shift(&self) -> A {
do self.check_out |v| {
let mut v = v;
let result = v.shift();
}
/// Reverse the elements in the list, in place
- fn reverse() {
+ fn reverse(&self) {
do self.check_out |v| {
let mut v = v;
vec::reverse(v);
}
/// Gives access to the vector as a slice with immutable contents
- fn borrow<R>(op: fn(x: &[A]) -> R) -> R {
+ fn borrow<R>(&self, op: fn(x: &[A]) -> R) -> R {
do self.check_out |v| {
let result = op(v);
self.give_back(v);
}
/// Gives access to the vector as a slice with mutable contents
- fn borrow_mut<R>(op: &fn(x: &mut [A]) -> R) -> R {
+ fn borrow_mut<R>(&self, op: &fn(x: &mut [A]) -> R) -> R {
do self.check_out |v| {
let mut v = v;
let result = op(v);
*
* Equivalent to `append_iter()` but potentially more efficient.
*/
- fn push_all(ts: &[const A]) {
+ fn push_all(&self, ts: &[const A]) {
self.push_slice(ts, 0u, vec::len(ts));
}
/// Appends elements from `from_idx` to `to_idx` (exclusive)
- fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) {
+ fn push_slice(&self, ts: &[const A], from_idx: uint, to_idx: uint) {
do self.swap |v| {
let mut v = v;
let new_len = vec::len(v) + to_idx - from_idx;
*
* See `unwrap()` if you do not wish to copy the contents.
*/
- pure fn get() -> ~[A] {
+ pure fn get(&self) -> ~[A] {
unsafe {
do self.check_out |v| {
let w = copy v;
/// Copy out an individual element
#[inline(always)]
- pure fn get_elt(idx: uint) -> A {
+ pure fn get_elt(&self, idx: uint) -> A {
self.check_not_borrowed();
return self.data[idx];
}
/// Overwrites the contents of the element at `idx` with `a`
- fn set_elt(idx: uint, a: A) {
+ fn set_elt(&self, idx: uint, a: A) {
self.check_not_borrowed();
self.data[idx] = a;
}
* growing the vector if necessary. New elements will be initialized
* with `initval`
*/
- fn grow_set_elt(idx: uint, initval: &A, val: A) {
+ fn grow_set_elt(&self, idx: uint, initval: &A, val: A) {
do self.swap |v| {
let mut v = v;
v.grow_set(idx, initval, val);
/// Returns the last element, failing if the vector is empty
#[inline(always)]
- pure fn last() -> A {
+ pure fn last(&self) -> A {
self.check_not_borrowed();
let length = self.len();
/// Iterates over the elements in reverse order
#[inline(always)]
- fn rev_each(f: fn(v: &A) -> bool) {
+ fn rev_each(&self, f: fn(v: &A) -> bool) {
do self.swap |v| {
// FIXME(#2263)---we should be able to write
// `vec::rev_each(v, f);` but we cannot write now
/// Iterates over the elements and indices in reverse order
#[inline(always)]
- fn rev_eachi(f: fn(uint, v: &A) -> bool) {
+ fn rev_eachi(&self, f: fn(uint, v: &A) -> bool) {
do self.swap |v| {
// FIXME(#2263)---we should be able to write
// `vec::rev_eachi(v, f);` but we cannot write now
* function and require most types to only implement the
* IterBytes trait, that feeds SipHash.
*/
- pure fn hash_keyed(k0: u64, k1: u64) -> u64;
+ pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64;
}
// When we have default methods, won't need this.
pub trait HashUtil {
- pure fn hash() -> u64;
+ pure fn hash(&self) -> u64;
}
impl<A:Hash> HashUtil for A {
#[inline(always)]
- pure fn hash() -> u64 { self.hash_keyed(0,0) }
+ pure fn hash(&self) -> u64 { self.hash_keyed(0,0) }
}
/// Streaming hash-functions should implement this.
pub trait Streaming {
- fn input((&[const u8]));
+ fn input(&self, (&[const u8]));
// These can be refactored some when we have default methods.
- fn result_bytes() -> ~[u8];
+ fn result_bytes(&self) -> ~[u8];
fn result_str() -> ~str;
- fn result_u64() -> u64;
- fn reset();
+ fn result_u64(&self) -> u64;
+ fn reset(&self);
}
impl<A:IterBytes> Hash for A {
#[inline(always)]
- pure fn hash_keyed(k0: u64, k1: u64) -> u64 {
+ pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64 {
unsafe {
let s = &State(k0, k1);
for self.iter_bytes(true) |bytes| {
impl Streaming for &SipState {
#[inline(always)]
- fn input(buf: &[const u8]) {
+ fn input(&self, buf: &[const u8]) {
self.write(buf);
}
#[inline(always)]
- fn result_u64() -> u64 {
+ fn result_u64(&self) -> u64 {
let mut v0 = self.v0;
let mut v1 = self.v1;
let mut v2 = self.v2;
return (v0 ^ v1 ^ v2 ^ v3);
}
- fn result_bytes() -> ~[u8] {
+ fn result_bytes(&self) -> ~[u8] {
let h = self.result_u64();
~[(h >> 0) as u8,
(h >> 8) as u8,
]
}
+ // IMPLICIT SELF WARNING: fix me!
fn result_str() -> ~str {
let r = self.result_bytes();
let mut s = ~"";
}
#[inline(always)]
- fn reset() {
+ fn reset(&self) {
self.length = 0;
self.v0 = self.k0 ^ 0x736f6d6570736575;
self.v1 = self.k1 ^ 0x646f72616e646f6d;
}
pub impl<T> Data<T> {
- fn borrow_mut<R>(op: &fn(t: &mut T) -> R) -> R {
+ fn borrow_mut<R>(&self, op: &fn(t: &mut T) -> R) -> R {
match self.mode {
Immutable => fail!(fmt!("%? currently immutable",
self.value)),
}
}
- pure fn borrow_const<R>(op: &fn(t: &const T) -> R) -> R {
+ pure fn borrow_const<R>(&self, op: &fn(t: &const T) -> R) -> R {
op(&const self.value)
}
- fn borrow_imm<R>(op: &fn(t: &T) -> R) -> R {
+ fn borrow_imm<R>(&self, op: &fn(t: &T) -> R) -> R {
match self.mode {
Mutable => fail!(fmt!("%? currently mutable",
self.value)),
pub trait GenericPath {
static pure fn from_str(&str) -> Self;
- pure fn dirname() -> ~str;
- pure fn filename() -> Option<~str>;
- pure fn filestem() -> Option<~str>;
- pure fn filetype() -> Option<~str>;
+ pure fn dirname(&self) -> ~str;
+ pure fn filename(&self) -> Option<~str>;
+ pure fn filestem(&self) -> Option<~str>;
+ pure fn filetype(&self) -> Option<~str>;
- pure fn with_dirname((&str)) -> Self;
- pure fn with_filename((&str)) -> Self;
- pure fn with_filestem((&str)) -> Self;
- pure fn with_filetype((&str)) -> Self;
+ pure fn with_dirname(&self, (&str)) -> Self;
+ pure fn with_filename(&self, (&str)) -> Self;
+ pure fn with_filestem(&self, (&str)) -> Self;
+ pure fn with_filetype(&self, (&str)) -> Self;
- pure fn dir_path() -> Self;
- pure fn file_path() -> Self;
+ pure fn dir_path(&self) -> Self;
+ pure fn file_path(&self) -> Self;
- pure fn push((&str)) -> Self;
- pure fn push_rel((&Self)) -> Self;
- pure fn push_many((&[~str])) -> Self;
- pure fn pop() -> Self;
+ pure fn push(&self, (&str)) -> Self;
+ pure fn push_rel(&self, (&Self)) -> Self;
+ pure fn push_many(&self, (&[~str])) -> Self;
+ pure fn pop(&self) -> Self;
- pure fn unsafe_join((&Self)) -> Self;
- pure fn is_restricted() -> bool;
+ pure fn unsafe_join(&self, (&Self)) -> Self;
+ pure fn is_restricted(&self) -> bool;
- pure fn normalize() -> Self;
+ pure fn normalize(&self) -> Self;
}
#[cfg(windows)]
components: components }
}
- pure fn dirname() -> ~str {
+ pure fn dirname(&self) -> ~str {
unsafe {
let s = self.dir_path().to_str();
if s.len() == 0 {
}
}
- pure fn filename() -> Option<~str> {
+ pure fn filename(&self) -> Option<~str> {
match self.components.len() {
0 => None,
n => Some(copy self.components[n - 1])
}
}
- pure fn filestem() -> Option<~str> {
+ pure fn filestem(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
}
}
- pure fn filetype() -> Option<~str> {
+ pure fn filetype(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
}
}
- pure fn with_dirname(d: &str) -> PosixPath {
+ pure fn with_dirname(&self, d: &str) -> PosixPath {
let dpath = PosixPath(d);
match self.filename() {
Some(ref f) => dpath.push(*f),
}
}
- pure fn with_filename(f: &str) -> PosixPath {
+ pure fn with_filename(&self, f: &str) -> PosixPath {
unsafe {
assert ! str::any(f, |c| windows::is_sep(c as u8));
self.dir_path().push(f)
}
}
- pure fn with_filestem(s: &str) -> PosixPath {
+ pure fn with_filestem(&self, s: &str) -> PosixPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
}
}
- pure fn with_filetype(t: &str) -> PosixPath {
+ pure fn with_filetype(&self, t: &str) -> PosixPath {
if t.len() == 0 {
match self.filestem() {
- None => copy self,
+ None => copy *self,
Some(ref s) => self.with_filename(*s)
}
} else {
}
}
- pure fn dir_path() -> PosixPath {
+ pure fn dir_path(&self) -> PosixPath {
if self.components.len() != 0 {
self.pop()
} else {
- copy self
+ copy *self
}
}
- pure fn file_path() -> PosixPath {
+ pure fn file_path(&self) -> PosixPath {
let cs = match self.filename() {
None => ~[],
Some(ref f) => ~[copy *f]
components: cs }
}
- pure fn push_rel(other: &PosixPath) -> PosixPath {
+ pure fn push_rel(&self, other: &PosixPath) -> PosixPath {
assert !other.is_absolute;
self.push_many(other.components)
}
- pure fn unsafe_join(other: &PosixPath) -> PosixPath {
+ pure fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
if other.is_absolute {
PosixPath { is_absolute: true,
components: copy other.components }
}
}
- pure fn is_restricted() -> bool {
+ pure fn is_restricted(&self) -> bool {
false
}
- pure fn push_many(cs: &[~str]) -> PosixPath {
+ pure fn push_many(&self, cs: &[~str]) -> PosixPath {
let mut v = copy self.components;
for cs.each |e| {
let mut ss = str::split_nonempty(
components: v }
}
- pure fn push(s: &str) -> PosixPath {
+ pure fn push(&self, s: &str) -> PosixPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
unsafe { v.push_all_move(ss); }
- PosixPath { components: v, ..copy self }
+ PosixPath { components: v, ..copy *self }
}
- pure fn pop() -> PosixPath {
+ pure fn pop(&self) -> PosixPath {
let mut cs = copy self.components;
if cs.len() != 0 {
unsafe { cs.pop(); }
//..self }
}
- pure fn normalize() -> PosixPath {
+ pure fn normalize(&self) -> PosixPath {
return PosixPath {
is_absolute: self.is_absolute,
components: normalize(self.components)
components: components }
}
- pure fn dirname() -> ~str {
+ pure fn dirname(&self) -> ~str {
unsafe {
let s = self.dir_path().to_str();
if s.len() == 0 {
}
}
- pure fn filename() -> Option<~str> {
+ pure fn filename(&self) -> Option<~str> {
match self.components.len() {
0 => None,
n => Some(copy self.components[n - 1])
}
}
- pure fn filestem() -> Option<~str> {
+ pure fn filestem(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
}
}
- pure fn filetype() -> Option<~str> {
+ pure fn filetype(&self) -> Option<~str> {
match self.filename() {
None => None,
Some(ref f) => {
}
}
- pure fn with_dirname(d: &str) -> WindowsPath {
+ pure fn with_dirname(&self, d: &str) -> WindowsPath {
let dpath = WindowsPath(d);
match self.filename() {
Some(ref f) => dpath.push(*f),
}
}
- pure fn with_filename(f: &str) -> WindowsPath {
+ pure fn with_filename(&self, f: &str) -> WindowsPath {
assert ! str::any(f, |c| windows::is_sep(c as u8));
self.dir_path().push(f)
}
- pure fn with_filestem(s: &str) -> WindowsPath {
+ pure fn with_filestem(&self, s: &str) -> WindowsPath {
match self.filetype() {
None => self.with_filename(s),
Some(ref t) => self.with_filename(str::from_slice(s) + *t)
}
}
- pure fn with_filetype(t: &str) -> WindowsPath {
+ pure fn with_filetype(&self, t: &str) -> WindowsPath {
if t.len() == 0 {
match self.filestem() {
- None => copy self,
+ None => copy *self,
Some(ref s) => self.with_filename(*s)
}
} else {
}
}
- pure fn dir_path() -> WindowsPath {
+ pure fn dir_path(&self) -> WindowsPath {
if self.components.len() != 0 {
self.pop()
} else {
- copy self
+ copy *self
}
}
- pure fn file_path() -> WindowsPath {
+ pure fn file_path(&self) -> WindowsPath {
let cs = match self.filename() {
None => ~[],
Some(ref f) => ~[copy *f]
components: cs }
}
- pure fn push_rel(other: &WindowsPath) -> WindowsPath {
+ pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
assert !other.is_absolute;
self.push_many(other.components)
}
- pure fn unsafe_join(other: &WindowsPath) -> WindowsPath {
+ pure fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
/* rhs not absolute is simple push */
if !other.is_absolute {
return self.push_many(other.components);
}
}
- pure fn is_restricted() -> bool {
+ pure fn is_restricted(&self) -> bool {
match self.filestem() {
Some(stem) => {
match stem.to_lower() {
}
}
- pure fn push_many(cs: &[~str]) -> WindowsPath {
+ pure fn push_many(&self, cs: &[~str]) -> WindowsPath {
let mut v = copy self.components;
for cs.each |e| {
let mut ss = str::split_nonempty(
}
}
- pure fn push(s: &str) -> WindowsPath {
+ pure fn push(&self, s: &str) -> WindowsPath {
let mut v = copy self.components;
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
unsafe { v.push_all_move(ss); }
- return WindowsPath { components: v, ..copy self }
+ return WindowsPath { components: v, ..copy *self }
}
- pure fn pop() -> WindowsPath {
+ pure fn pop(&self) -> WindowsPath {
let mut cs = copy self.components;
if cs.len() != 0 {
unsafe { cs.pop(); }
}
}
- pure fn normalize() -> WindowsPath {
+ pure fn normalize(&self) -> WindowsPath {
return WindowsPath {
host: copy self.host,
device: match self.device {
pub impl PacketHeader {
// Returns the old state.
- unsafe fn mark_blocked(this: *rust_task) -> State {
+ unsafe fn mark_blocked(&self, this: *rust_task) -> State {
rustrt::rust_task_ref(this);
let old_task = swap_task(&mut self.blocked_task, this);
assert old_task.is_null();
swap_state_acq(&mut self.state, Blocked)
}
- unsafe fn unblock() {
+ unsafe fn unblock(&self) {
let old_task = swap_task(&mut self.blocked_task, ptr::null());
if !old_task.is_null() {
unsafe {
// unsafe because this can do weird things to the space/time
// continuum. It ends making multiple unique pointers to the same
// thing. You'll proobably want to forget them when you're done.
- unsafe fn buf_header() -> ~BufferHeader {
+ unsafe fn buf_header(&self) -> ~BufferHeader {
assert self.buffer.is_not_null();
reinterpret_cast(&self.buffer)
}
- fn set_buffer<T:Owned>(b: ~Buffer<T>) {
+ fn set_buffer<T:Owned>(&self, b: ~Buffer<T>) {
unsafe {
self.buffer = reinterpret_cast(&b);
}
#[doc(hidden)]
pub trait HasBuffer {
- fn set_buffer(b: *libc::c_void);
+ fn set_buffer(&self, b: *libc::c_void);
}
impl<T:Owned> HasBuffer for Packet<T> {
- fn set_buffer(b: *libc::c_void) {
+ fn set_buffer(&self, b: *libc::c_void) {
self.header.buffer = b;
}
}
#[doc(hidden)]
pub trait Selectable {
- pure fn header() -> *PacketHeader;
+ pure fn header(&self) -> *PacketHeader;
}
impl Selectable for *PacketHeader {
- pure fn header() -> *PacketHeader { self }
+ pure fn header(&self) -> *PacketHeader { *self }
}
/// Returns the index of an endpoint that is ready to receive.
}
pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
- fn unwrap() -> *Packet<T> {
+ fn unwrap(&self) -> *Packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(p)
}
- pure fn header() -> *PacketHeader {
+ pure fn header(&self) -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
}
}
- fn reuse_buffer() -> BufferResource<Tbuffer> {
+ fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
//error!("send reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
}
pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
- fn unwrap() -> *Packet<T> {
+ fn unwrap(&self) -> *Packet<T> {
let mut p = None;
p <-> self.p;
option::unwrap(p)
}
- fn reuse_buffer() -> BufferResource<Tbuffer> {
+ fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
//error!("recv reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
}
impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
- pure fn header() -> *PacketHeader {
+ pure fn header(&self) -> *PacketHeader {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
}
pub trait Ptr<T> {
- pure fn is_null() -> bool;
- pure fn is_not_null() -> bool;
- pure fn offset(count: uint) -> Self;
+ pure fn is_null(&self) -> bool;
+ pure fn is_not_null(&self) -> bool;
+ pure fn offset(&self, count: uint) -> Self;
}
/// Extension methods for immutable pointers
impl<T> Ptr<T> for *T {
/// Returns true if the pointer is equal to the null pointer.
#[inline(always)]
- pure fn is_null() -> bool { is_null(self) }
+ pure fn is_null(&self) -> bool { is_null(*self) }
/// Returns true if the pointer is not equal to the null pointer.
#[inline(always)]
- pure fn is_not_null() -> bool { is_not_null(self) }
+ pure fn is_not_null(&self) -> bool { is_not_null(*self) }
/// Calculates the offset from a pointer.
#[inline(always)]
- pure fn offset(count: uint) -> *T { offset(self, count) }
+ pure fn offset(&self, count: uint) -> *T { offset(*self, count) }
}
/// Extension methods for mutable pointers
impl<T> Ptr<T> for *mut T {
/// Returns true if the pointer is equal to the null pointer.
#[inline(always)]
- pure fn is_null() -> bool { is_null(self) }
+ pure fn is_null(&self) -> bool { is_null(*self) }
/// Returns true if the pointer is not equal to the null pointer.
#[inline(always)]
- pure fn is_not_null() -> bool { is_not_null(self) }
+ pure fn is_not_null(&self) -> bool { is_not_null(*self) }
/// Calculates the offset from a mutable pointer.
#[inline(always)]
- pure fn offset(count: uint) -> *mut T { mut_offset(self, count) }
+ pure fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) }
}
// Equality for pointers
/// A random number generator
pub trait Rng {
/// Return the next random integer
- fn next() -> u32;
+ fn next(&self) -> u32;
}
/// A value with a particular weight compared to other values
/// Extension methods for random number generators
pub impl Rng {
/// Return a random value for a Rand type
- fn gen<T:Rand>() -> T {
- Rand::rand(self)
+ fn gen<T:Rand>(&self) -> T {
+ Rand::rand(*self)
}
/// Return a random int
- fn gen_int() -> int {
+ fn gen_int(&self) -> int {
self.gen_i64() as int
}
* Return an int randomly chosen from the range [start, end),
* failing if start >= end
*/
- fn gen_int_range(start: int, end: int) -> int {
+ fn gen_int_range(&self, start: int, end: int) -> int {
assert start < end;
start + int::abs(self.gen_int() % (end - start))
}
/// Return a random i8
- fn gen_i8() -> i8 {
+ fn gen_i8(&self) -> i8 {
self.next() as i8
}
/// Return a random i16
- fn gen_i16() -> i16 {
+ fn gen_i16(&self) -> i16 {
self.next() as i16
}
/// Return a random i32
- fn gen_i32() -> i32 {
+ fn gen_i32(&self) -> i32 {
self.next() as i32
}
/// Return a random i64
- fn gen_i64() -> i64 {
+ fn gen_i64(&self) -> i64 {
(self.next() as i64 << 32) | self.next() as i64
}
/// Return a random uint
- fn gen_uint() -> uint {
+ fn gen_uint(&self) -> uint {
self.gen_u64() as uint
}
* Return a uint randomly chosen from the range [start, end),
* failing if start >= end
*/
- fn gen_uint_range(start: uint, end: uint) -> uint {
+ fn gen_uint_range(&self, start: uint, end: uint) -> uint {
assert start < end;
start + (self.gen_uint() % (end - start))
}
/// Return a random u8
- fn gen_u8() -> u8 {
+ fn gen_u8(&self) -> u8 {
self.next() as u8
}
/// Return a random u16
- fn gen_u16() -> u16 {
+ fn gen_u16(&self) -> u16 {
self.next() as u16
}
/// Return a random u32
- fn gen_u32() -> u32 {
+ fn gen_u32(&self) -> u32 {
self.next()
}
/// Return a random u64
- fn gen_u64() -> u64 {
+ fn gen_u64(&self) -> u64 {
(self.next() as u64 << 32) | self.next() as u64
}
/// Return a random float in the interval [0,1]
- fn gen_float() -> float {
+ fn gen_float(&self) -> float {
self.gen_f64() as float
}
/// Return a random f32 in the interval [0,1]
- fn gen_f32() -> f32 {
+ fn gen_f32(&self) -> f32 {
self.gen_f64() as f32
}
/// Return a random f64 in the interval [0,1]
- fn gen_f64() -> f64 {
+ fn gen_f64(&self) -> f64 {
let u1 = self.next() as f64;
let u2 = self.next() as f64;
let u3 = self.next() as f64;
}
/// Return a random char
- fn gen_char() -> char {
+ fn gen_char(&self) -> char {
self.next() as char
}
/**
* Return a char randomly chosen from chars, failing if chars is empty
*/
- fn gen_char_from(chars: &str) -> char {
+ fn gen_char_from(&self, chars: &str) -> char {
assert !chars.is_empty();
self.choose(str::chars(chars))
}
/// Return a random bool
- fn gen_bool() -> bool {
+ fn gen_bool(&self) -> bool {
self.next() & 1u32 == 1u32
}
/// Return a bool with a 1 in n chance of true
- fn gen_weighted_bool(n: uint) -> bool {
+ fn gen_weighted_bool(&self, n: uint) -> bool {
if n == 0u {
true
} else {
/**
* Return a random string of the specified length composed of A-Z,a-z,0-9
*/
- fn gen_str(len: uint) -> ~str {
+ fn gen_str(&self, len: uint) -> ~str {
let charset = ~"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789";
}
/// Return a random byte string of the specified length
- fn gen_bytes(len: uint) -> ~[u8] {
+ fn gen_bytes(&self, len: uint) -> ~[u8] {
do vec::from_fn(len) |_i| {
self.gen_u8()
}
}
/// Choose an item randomly, failing if values is empty
- fn choose<T:Copy>(values: &[T]) -> T {
+ fn choose<T:Copy>(&self, values: &[T]) -> T {
self.choose_option(values).get()
}
/// Choose Some(item) randomly, returning None if values is empty
- fn choose_option<T:Copy>(values: &[T]) -> Option<T> {
+ fn choose_option<T:Copy>(&self, values: &[T]) -> Option<T> {
if values.is_empty() {
None
} else {
* Choose an item respecting the relative weights, failing if the sum of
* the weights is 0
*/
- fn choose_weighted<T:Copy>(v : &[Weighted<T>]) -> T {
+ fn choose_weighted<T:Copy>(&self, v : &[Weighted<T>]) -> T {
self.choose_weighted_option(v).get()
}
* Choose Some(item) respecting the relative weights, returning none if
* the sum of the weights is 0
*/
- fn choose_weighted_option<T:Copy>(v: &[Weighted<T>]) -> Option<T> {
+ fn choose_weighted_option<T:Copy>(&self, v: &[Weighted<T>]) -> Option<T> {
let mut total = 0u;
for v.each |item| {
total += item.weight;
* Return a vec containing copies of the items, in order, where
* the weight of the item determines how many copies there are
*/
- fn weighted_vec<T:Copy>(v: &[Weighted<T>]) -> ~[T] {
+ fn weighted_vec<T:Copy>(&self, v: &[Weighted<T>]) -> ~[T] {
let mut r = ~[];
for v.each |item| {
for uint::range(0u, item.weight) |_i| {
}
/// Shuffle a vec
- fn shuffle<T:Copy>(values: &[T]) -> ~[T] {
+ fn shuffle<T:Copy>(&self, values: &[T]) -> ~[T] {
let mut m = vec::from_slice(values);
self.shuffle_mut(m);
m
}
/// Shuffle a mutable vec in place
- fn shuffle_mut<T>(values: &mut [T]) {
+ fn shuffle_mut<T>(&self, values: &mut [T]) {
let mut i = values.len();
while i >= 2u {
// invariant: elements with index >= i have been locked in place.
}
impl Rng for @RandRes {
- fn next() -> u32 {
+ fn next(&self) -> u32 {
unsafe {
return rustrt::rand_next((*self).rng);
}
}
impl Rng for XorShiftState {
- fn next() -> u32 {
+ fn next(&self) -> u32 {
let x = self.x;
let mut t = x ^ (x << 11);
self.x = self.y;
* then build a MovePtrAdaptor wrapped around your struct.
*/
pub trait MovePtr {
- fn move_ptr(adjustment: fn(*c_void) -> *c_void);
- fn push_ptr();
- fn pop_ptr();
+ fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void);
+ fn push_ptr(&self);
+ fn pop_ptr(&self);
}
/// Helper function for alignment calculation.
pub impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
#[inline(always)]
- fn bump(sz: uint) {
+ fn bump(&self, sz: uint) {
do self.inner.move_ptr() |p| {
((p as uint) + sz) as *c_void
};
}
#[inline(always)]
- fn align(a: uint) {
+ fn align(&self, a: uint) {
do self.inner.move_ptr() |p| {
align(p as uint, a) as *c_void
};
}
#[inline(always)]
- fn align_to<T>() {
+ fn align_to<T>(&self) {
self.align(sys::min_align_of::<T>());
}
#[inline(always)]
- fn bump_past<T>() {
+ fn bump_past<T>(&self) {
self.bump(sys::size_of::<T>());
}
}
/// Helpers
trait EscapedCharWriter {
- fn write_escaped_char(ch: char);
+ fn write_escaped_char(&self, ch: char);
}
impl EscapedCharWriter for Writer {
- fn write_escaped_char(ch: char) {
+ fn write_escaped_char(&self, ch: char) {
match ch {
'\t' => self.write_str("\\t"),
'\r' => self.write_str("\\r"),
/// Representations
trait Repr {
- fn write_repr(writer: @Writer);
+ fn write_repr(&self, writer: @Writer);
}
impl Repr for () {
- fn write_repr(writer: @Writer) { writer.write_str("()"); }
+ fn write_repr(&self, writer: @Writer) { writer.write_str("()"); }
}
impl Repr for bool {
- fn write_repr(writer: @Writer) {
- writer.write_str(if self { "true" } else { "false" })
+ fn write_repr(&self, writer: @Writer) {
+ writer.write_str(if *self { "true" } else { "false" })
}
}
impl Repr for int {
- fn write_repr(writer: @Writer) { writer.write_int(self); }
+ fn write_repr(&self, writer: @Writer) { writer.write_int(*self); }
}
impl Repr for i8 {
- fn write_repr(writer: @Writer) { writer.write_int(self as int); }
+ fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); }
}
impl Repr for i16 {
- fn write_repr(writer: @Writer) { writer.write_int(self as int); }
+ fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); }
}
impl Repr for i32 {
- fn write_repr(writer: @Writer) { writer.write_int(self as int); }
+ fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); }
}
impl Repr for i64 {
// FIXME #4424: This can lose precision.
- fn write_repr(writer: @Writer) { writer.write_int(self as int); }
+ fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); }
}
impl Repr for uint {
- fn write_repr(writer: @Writer) { writer.write_uint(self); }
+ fn write_repr(&self, writer: @Writer) { writer.write_uint(*self); }
}
impl Repr for u8 {
- fn write_repr(writer: @Writer) { writer.write_uint(self as uint); }
+ fn write_repr(&self, writer: @Writer) {
+ writer.write_uint(*self as uint);
+ }
}
impl Repr for u16 {
- fn write_repr(writer: @Writer) { writer.write_uint(self as uint); }
+ fn write_repr(&self, writer: @Writer) {
+ writer.write_uint(*self as uint);
+ }
}
impl Repr for u32 {
- fn write_repr(writer: @Writer) { writer.write_uint(self as uint); }
+ fn write_repr(&self, writer: @Writer) {
+ writer.write_uint(*self as uint);
+ }
}
impl Repr for u64 {
// FIXME #4424: This can lose precision.
- fn write_repr(writer: @Writer) { writer.write_uint(self as uint); }
+ fn write_repr(&self, writer: @Writer) {
+ writer.write_uint(*self as uint);
+ }
}
impl Repr for float {
// FIXME #4423: This mallocs.
- fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); }
+ fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); }
}
impl Repr for f32 {
// FIXME #4423 This mallocs.
- fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); }
+ fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); }
}
impl Repr for f64 {
// FIXME #4423: This mallocs.
- fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); }
+ fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); }
}
impl Repr for char {
- fn write_repr(writer: @Writer) { writer.write_char(self); }
+ fn write_repr(&self, writer: @Writer) { writer.write_char(*self); }
}
impl MovePtr for ReprVisitor {
#[inline(always)]
- fn move_ptr(adjustment: fn(*c_void) -> *c_void) {
+ fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void) {
self.ptr = adjustment(self.ptr);
}
- fn push_ptr() {
+ fn push_ptr(&self) {
self.ptr_stk.push(self.ptr);
}
- fn pop_ptr() {
+ fn pop_ptr(&self) {
self.ptr = self.ptr_stk.pop();
}
}
// Various helpers for the TyVisitor impl
#[inline(always)]
- fn get<T>(f: fn(&T)) -> bool {
+ fn get<T>(&self, f: fn(&T)) -> bool {
unsafe {
f(transmute::<*c_void,&T>(copy self.ptr));
}
}
#[inline(always)]
- fn bump(sz: uint) {
+ fn bump(&self, sz: uint) {
do self.move_ptr() |p| {
((p as uint) + sz) as *c_void
};
}
#[inline(always)]
- fn bump_past<T>() {
+ fn bump_past<T>(&self) {
self.bump(sys::size_of::<T>());
}
#[inline(always)]
- fn visit_inner(inner: *TyDesc) -> bool {
+ fn visit_inner(&self, inner: *TyDesc) -> bool {
self.visit_ptr_inner(self.ptr, inner)
}
#[inline(always)]
- fn visit_ptr_inner(ptr: *c_void, inner: *TyDesc) -> bool {
+ fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool {
unsafe {
let mut u = ReprVisitor(ptr, self.writer);
let v = reflect::MovePtrAdaptor(u);
}
#[inline(always)]
- fn write<T:Repr>() -> bool {
+ fn write<T:Repr>(&self) -> bool {
do self.get |v:&T| {
v.write_repr(self.writer);
}
}
- fn write_escaped_slice(slice: &str) {
+ fn write_escaped_slice(&self, slice: &str) {
self.writer.write_char('"');
for str::chars_each(slice) |ch| {
self.writer.write_escaped_char(ch);
self.writer.write_char('"');
}
- fn write_mut_qualifier(mtbl: uint) {
+ fn write_mut_qualifier(&self, mtbl: uint) {
if mtbl == 0 {
self.writer.write_str("mut ");
} else if mtbl == 1 {
}
}
- fn write_vec_range(mtbl: uint, ptr: *u8, len: uint,
+ fn write_vec_range(&self, mtbl: uint, ptr: *u8, len: uint,
inner: *TyDesc) -> bool {
let mut p = ptr;
let end = ptr::offset(p, len);
true
}
- fn write_unboxed_vec_repr(mtbl: uint, v: &UnboxedVecRepr,
+ fn write_unboxed_vec_repr(&self, mtbl: uint, v: &UnboxedVecRepr,
inner: *TyDesc) -> bool {
self.write_vec_range(mtbl, ptr::to_unsafe_ptr(&v.data),
v.fill, inner)
}
pub trait Trimmable {
- pure fn trim() -> Self;
- pure fn trim_left() -> Self;
- pure fn trim_right() -> Self;
+ pure fn trim(&self) -> Self;
+ pure fn trim_left(&self) -> Self;
+ pure fn trim_right(&self) -> Self;
}
/// Extension methods for strings
impl Trimmable for ~str {
/// Returns a string with leading and trailing whitespace removed
#[inline]
- pure fn trim() -> ~str { trim(self) }
+ pure fn trim(&self) -> ~str { trim(*self) }
/// Returns a string with leading whitespace removed
#[inline]
- pure fn trim_left() -> ~str { trim_left(self) }
+ pure fn trim_left(&self) -> ~str { trim_left(*self) }
/// Returns a string with trailing whitespace removed
#[inline]
- pure fn trim_right() -> ~str { trim_right(self) }
+ pure fn trim_right(&self) -> ~str { trim_right(*self) }
}
#[cfg(notest)]
pub mod traits {}
pub trait StrSlice {
- pure fn all(it: fn(char) -> bool) -> bool;
- pure fn any(it: fn(char) -> bool) -> bool;
- pure fn contains(needle: &a/str) -> bool;
- pure fn contains_char(needle: char) -> bool;
- pure fn each(it: fn(u8) -> bool);
- pure fn eachi(it: fn(uint, u8) -> bool);
- pure fn each_char(it: fn(char) -> bool);
- pure fn each_chari(it: fn(uint, char) -> bool);
- pure fn ends_with(needle: &str) -> bool;
- pure fn is_empty() -> bool;
- pure fn is_whitespace() -> bool;
- pure fn is_alphanumeric() -> bool;
- pure fn len() -> uint;
- pure fn slice(begin: uint, end: uint) -> ~str;
- pure fn split(sepfn: fn(char) -> bool) -> ~[~str];
- pure fn split_char(sep: char) -> ~[~str];
- pure fn split_str(sep: &a/str) -> ~[~str];
- pure fn starts_with(needle: &a/str) -> bool;
- pure fn substr(begin: uint, n: uint) -> ~str;
- pure fn to_lower() -> ~str;
- pure fn to_upper() -> ~str;
- pure fn escape_default() -> ~str;
- pure fn escape_unicode() -> ~str;
- pure fn trim() -> ~str;
- pure fn trim_left() -> ~str;
- pure fn trim_right() -> ~str;
- pure fn to_owned() -> ~str;
- pure fn to_managed() -> @str;
- pure fn char_at(i: uint) -> char;
+ pure fn all(&self, it: fn(char) -> bool) -> bool;
+ pure fn any(&self, it: fn(char) -> bool) -> bool;
+ pure fn contains(&self, needle: &a/str) -> bool;
+ pure fn contains_char(&self, needle: char) -> bool;
+ pure fn each(&self, it: fn(u8) -> bool);
+ pure fn eachi(&self, it: fn(uint, u8) -> bool);
+ pure fn each_char(&self, it: fn(char) -> bool);
+ pure fn each_chari(&self, it: fn(uint, char) -> bool);
+ pure fn ends_with(&self, needle: &str) -> bool;
+ pure fn is_empty(&self) -> bool;
+ pure fn is_whitespace(&self) -> bool;
+ pure fn is_alphanumeric(&self) -> bool;
+ pure fn len(&self) -> uint;
+ pure fn slice(&self, begin: uint, end: uint) -> ~str;
+ pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str];
+ pure fn split_char(&self, sep: char) -> ~[~str];
+ pure fn split_str(&self, sep: &a/str) -> ~[~str];
+ pure fn starts_with(&self, needle: &a/str) -> bool;
+ pure fn substr(&self, begin: uint, n: uint) -> ~str;
+ pure fn to_lower(&self) -> ~str;
+ pure fn to_upper(&self) -> ~str;
+ pure fn escape_default(&self) -> ~str;
+ pure fn escape_unicode(&self) -> ~str;
+ pure fn trim(&self) -> ~str;
+ pure fn trim_left(&self) -> ~str;
+ pure fn trim_right(&self) -> ~str;
+ pure fn to_owned(&self) -> ~str;
+ pure fn to_managed(&self) -> @str;
+ pure fn char_at(&self, i: uint) -> char;
}
/// Extension methods for strings
* contains no characters
*/
#[inline]
- pure fn all(it: fn(char) -> bool) -> bool { all(self, it) }
+ pure fn all(&self, it: fn(char) -> bool) -> bool { all(*self, it) }
/**
* Return true if a predicate matches any character (and false if it
* matches none or there are no characters)
*/
#[inline]
- pure fn any(it: fn(char) -> bool) -> bool { any(self, it) }
+ pure fn any(&self, it: fn(char) -> bool) -> bool { any(*self, it) }
/// Returns true if one string contains another
#[inline]
- pure fn contains(needle: &a/str) -> bool { contains(self, needle) }
+ pure fn contains(&self, needle: &a/str) -> bool {
+ contains(*self, needle)
+ }
/// Returns true if a string contains a char
#[inline]
- pure fn contains_char(needle: char) -> bool {
- contains_char(self, needle)
+ pure fn contains_char(&self, needle: char) -> bool {
+ contains_char(*self, needle)
}
/// Iterate over the bytes in a string
#[inline]
- pure fn each(it: fn(u8) -> bool) { each(self, it) }
+ pure fn each(&self, it: fn(u8) -> bool) { each(*self, it) }
/// Iterate over the bytes in a string, with indices
#[inline]
- pure fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) }
+ pure fn eachi(&self, it: fn(uint, u8) -> bool) { eachi(*self, it) }
/// Iterate over the chars in a string
#[inline]
- pure fn each_char(it: fn(char) -> bool) { each_char(self, it) }
+ pure fn each_char(&self, it: fn(char) -> bool) { each_char(*self, it) }
/// Iterate over the chars in a string, with indices
#[inline]
- pure fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) }
+ pure fn each_chari(&self, it: fn(uint, char) -> bool) {
+ each_chari(*self, it)
+ }
/// Returns true if one string ends with another
#[inline]
- pure fn ends_with(needle: &str) -> bool { ends_with(self, needle) }
+ pure fn ends_with(&self, needle: &str) -> bool {
+ ends_with(*self, needle)
+ }
/// Returns true if the string has length 0
#[inline]
- pure fn is_empty() -> bool { is_empty(self) }
+ pure fn is_empty(&self) -> bool { is_empty(*self) }
/**
* Returns true if the string contains only whitespace
*
* Whitespace characters are determined by `char::is_whitespace`
*/
#[inline]
- pure fn is_whitespace() -> bool { is_whitespace(self) }
+ pure fn is_whitespace(&self) -> bool { is_whitespace(*self) }
/**
* Returns true if the string contains only alphanumerics
*
* Alphanumeric characters are determined by `char::is_alphanumeric`
*/
#[inline]
- pure fn is_alphanumeric() -> bool { is_alphanumeric(self) }
+ pure fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) }
#[inline]
/// Returns the size in bytes not counting the null terminator
- pure fn len() -> uint { len(self) }
+ pure fn len(&self) -> uint { len(*self) }
/**
* Returns a slice of the given string from the byte range
* [`begin`..`end`)
* beyond the last character of the string
*/
#[inline]
- pure fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) }
+ pure fn slice(&self, begin: uint, end: uint) -> ~str {
+ slice(*self, begin, end)
+ }
/// Splits a string into substrings using a character function
#[inline]
- pure fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) }
+ pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str] {
+ split(*self, sepfn)
+ }
/**
* Splits a string into substrings at each occurrence of a given character
*/
#[inline]
- pure fn split_char(sep: char) -> ~[~str] { split_char(self, sep) }
+ pure fn split_char(&self, sep: char) -> ~[~str] { split_char(*self, sep) }
/**
* Splits a string into a vector of the substrings separated by a given
* string
*/
#[inline]
- pure fn split_str(sep: &a/str) -> ~[~str] { split_str(self, sep) }
+ pure fn split_str(&self, sep: &a/str) -> ~[~str] { split_str(*self, sep) }
/// Returns true if one string starts with another
#[inline]
- pure fn starts_with(needle: &a/str) -> bool { starts_with(self, needle) }
+ pure fn starts_with(&self, needle: &a/str) -> bool {
+ starts_with(*self, needle)
+ }
/**
* Take a substring of another.
*
* `begin`.
*/
#[inline]
- pure fn substr(begin: uint, n: uint) -> ~str { substr(self, begin, n) }
+ pure fn substr(&self, begin: uint, n: uint) -> ~str {
+ substr(*self, begin, n)
+ }
/// Convert a string to lowercase
#[inline]
- pure fn to_lower() -> ~str { to_lower(self) }
+ pure fn to_lower(&self) -> ~str { to_lower(*self) }
/// Convert a string to uppercase
#[inline]
- pure fn to_upper() -> ~str { to_upper(self) }
+ pure fn to_upper(&self) -> ~str { to_upper(*self) }
/// Escape each char in `s` with char::escape_default.
#[inline]
- pure fn escape_default() -> ~str { escape_default(self) }
+ pure fn escape_default(&self) -> ~str { escape_default(*self) }
/// Escape each char in `s` with char::escape_unicode.
#[inline]
- pure fn escape_unicode() -> ~str { escape_unicode(self) }
+ pure fn escape_unicode(&self) -> ~str { escape_unicode(*self) }
/// Returns a string with leading and trailing whitespace removed
#[inline]
- pure fn trim() -> ~str { trim(self) }
+ pure fn trim(&self) -> ~str { trim(*self) }
/// Returns a string with leading whitespace removed
#[inline]
- pure fn trim_left() -> ~str { trim_left(self) }
+ pure fn trim_left(&self) -> ~str { trim_left(*self) }
/// Returns a string with trailing whitespace removed
#[inline]
- pure fn trim_right() -> ~str { trim_right(self) }
+ pure fn trim_right(&self) -> ~str { trim_right(*self) }
#[inline]
- pure fn to_owned() -> ~str { self.slice(0, self.len()) }
+ pure fn to_owned(&self) -> ~str { self.slice(0, self.len()) }
#[inline]
- pure fn to_managed() -> @str {
+ pure fn to_managed(&self) -> @str {
let v = at_vec::from_fn(self.len() + 1, |i| {
if i == self.len() { 0 } else { self[i] }
});
}
#[inline]
- pure fn char_at(i: uint) -> char { char_at(self, i) }
+ pure fn char_at(&self, i: uint) -> char { char_at(*self, i) }
}
pub trait OwnedStr {
#[doc(hidden)] // FIXME #3538
priv impl TaskBuilder {
- fn consume() -> TaskBuilder {
+ fn consume(&self) -> TaskBuilder {
if self.consumed {
fail!(~"Cannot copy a task_builder"); // Fake move mode on self
}
* Decouple the child task's failure from the parent's. If either fails,
* the other will not be killed.
*/
- fn unlinked() -> TaskBuilder {
+ fn unlinked(&self) -> TaskBuilder {
let notify_chan = replace(&mut self.opts.notify_chan, None);
TaskBuilder {
opts: TaskOpts {
* child's failure will not kill the parent, but the parent's will kill
* the child.
*/
- fn supervised() -> TaskBuilder {
+ fn supervised(&self) -> TaskBuilder {
let notify_chan = replace(&mut self.opts.notify_chan, None);
TaskBuilder {
opts: TaskOpts {
* Link the child task's and parent task's failures. If either fails, the
* other will be killed.
*/
- fn linked() -> TaskBuilder {
+ fn linked(&self) -> TaskBuilder {
let notify_chan = replace(&mut self.opts.notify_chan, None);
TaskBuilder {
opts: TaskOpts {
* # Failure
* Fails if a future_result was already set for this task.
*/
- fn future_result(blk: fn(v: Port<TaskResult>)) -> TaskBuilder {
+ fn future_result(&self, blk: fn(v: Port<TaskResult>)) -> TaskBuilder {
// FIXME (#3725): Once linked failure and notification are
// handled in the library, I can imagine implementing this by just
// registering an arbitrary number of task::on_exit handlers and
}
}
/// Configure a custom scheduler mode for the task.
- fn sched_mode(mode: SchedMode) -> TaskBuilder {
+ fn sched_mode(&self, mode: SchedMode) -> TaskBuilder {
let notify_chan = replace(&mut self.opts.notify_chan, None);
TaskBuilder {
opts: TaskOpts {
* generator by applying the task body which results from the
* existing body generator to the new body generator.
*/
- fn add_wrapper(wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder {
+ fn add_wrapper(&self, wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder {
let prev_gen_body = self.gen_body;
let notify_chan = replace(&mut self.opts.notify_chan, None);
TaskBuilder {
* When spawning into a new scheduler, the number of threads requested
* must be greater than zero.
*/
- fn spawn(f: ~fn()) {
+ fn spawn(&self, f: ~fn()) {
let notify_chan = replace(&mut self.opts.notify_chan, None);
let x = self.consume();
let opts = TaskOpts {
spawn::spawn_raw(opts, (x.gen_body)(f));
}
/// Runs a task, while transfering ownership of one argument to the child.
- fn spawn_with<A:Owned>(arg: A, f: ~fn(v: A)) {
+ fn spawn_with<A:Owned>(&self, arg: A, f: ~fn(v: A)) {
let arg = Cell(arg);
do self.spawn {
f(arg.take());
* # Failure
* Fails if a future_result was already set for this task.
*/
- fn try<T:Owned>(f: ~fn() -> T) -> Result<T,()> {
+ fn try<T:Owned>(&self, f: ~fn() -> T) -> Result<T,()> {
let (po, ch) = stream::<T>();
let mut result = None;
use vec;
pub trait CopyableTuple<T, U> {
- pure fn first() -> T;
- pure fn second() -> U;
- pure fn swap() -> (U, T);
+ pure fn first(&self) -> T;
+ pure fn second(&self) -> U;
+ pure fn swap(&self) -> (U, T);
}
impl<T:Copy,U:Copy> CopyableTuple<T, U> for (T, U) {
/// Return the first element of self
#[inline(always)]
- pure fn first() -> T {
- let (t, _) = self;
+ pure fn first(&self) -> T {
+ let (t, _) = *self;
return t;
}
/// Return the second element of self
#[inline(always)]
- pure fn second() -> U {
- let (_, u) = self;
+ pure fn second(&self) -> U {
+ let (_, u) = *self;
return u;
}
/// Return the results of swapping the two elements of self
#[inline(always)]
- pure fn swap() -> (U, T) {
- let (t, u) = self;
+ pure fn swap(&self) -> (U, T) {
+ let (t, u) = *self;
return (u, t);
}
}
pub impl<T> Parsed<T> {
- static pure fn new(val: T, next: uint) -> Parsed<T> {
+ static pure fn new(&self, val: T, next: uint) -> Parsed<T> {
Parsed {val: val, next: next}
}
}
}
impl<T:Owned,U:Owned> GenericChan<T> for DuplexStream<T, U> {
- fn send(x: T) {
+ fn send(&self, x: T) {
self.chan.send(x)
}
}
impl<T:Owned,U:Owned> GenericSmartChan<T> for DuplexStream<T, U> {
- fn try_send(x: T) -> bool {
+ fn try_send(&self, x: T) -> bool {
self.chan.try_send(x)
}
}
impl<T:Owned,U:Owned> GenericPort<U> for DuplexStream<T, U> {
- fn recv() -> U {
+ fn recv(&self) -> U {
self.port.recv()
}
- fn try_recv() -> Option<U> {
+ fn try_recv(&self) -> Option<U> {
self.port.try_recv()
}
}
impl<T:Owned,U:Owned> Peekable<U> for DuplexStream<T, U> {
- pure fn peek() -> bool {
+ pure fn peek(&self) -> bool {
self.port.peek()
}
}
impl<T:Owned,U:Owned> Selectable for DuplexStream<T, U> {
- pure fn header() -> *pipes::PacketHeader {
+ pure fn header(&self) -> *pipes::PacketHeader {
self.port.header()
}
}
const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD];
impl<T,U:Unflattener<T>,P:BytePort> GenericPort<T> for FlatPort<T, U, P> {
- fn recv() -> T {
+ fn recv(&self) -> T {
match self.try_recv() {
Some(val) => val,
None => fail!(~"port is closed")
}
}
- fn try_recv() -> Option<T> {
+ fn try_recv(&self) -> Option<T> {
let command = match self.byte_port.try_recv(CONTINUE.len()) {
Some(c) => c,
None => {
}
impl<T,F:Flattener<T>,C:ByteChan> GenericChan<T> for FlatChan<T, F, C> {
- fn send(val: T) {
+ fn send(&self, val: T) {
self.byte_chan.send(CONTINUE.to_vec());
let bytes = self.flattener.flatten(val);
let len = bytes.len() as u64;