libstd: rename c_vec::size to len.
This commit is contained in:
@@ -31,7 +31,7 @@ taken to ensure that a reference to the c_vec::t is still held if needed.
|
|||||||
export t;
|
export t;
|
||||||
export create, create_with_dtor;
|
export create, create_with_dtor;
|
||||||
export get, set;
|
export get, set;
|
||||||
export size;
|
export len;
|
||||||
export ptr;
|
export ptr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -43,7 +43,7 @@ export ptr;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
tag t<T> {
|
tag t<T> {
|
||||||
t({ base: *mutable T, size: uint, rsrc: @dtor_res});
|
t({ base: *mutable T, len: uint, rsrc: @dtor_res});
|
||||||
}
|
}
|
||||||
|
|
||||||
resource dtor_res(dtor: option::t<fn@()>) {
|
resource dtor_res(dtor: option::t<fn@()>) {
|
||||||
@@ -60,16 +60,16 @@ resource dtor_res(dtor: option::t<fn@()>) {
|
|||||||
/*
|
/*
|
||||||
Function: create
|
Function: create
|
||||||
|
|
||||||
Create a c_vec::t from a native buffer with a given size.
|
Create a c_vec::t from a native buffer with a given length.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
|
||||||
base - A native pointer to a buffer
|
base - A native pointer to a buffer
|
||||||
size - The number of elements in the buffer
|
len - The number of elements in the buffer
|
||||||
*/
|
*/
|
||||||
unsafe fn create<T>(base: *mutable T, size: uint) -> t<T> {
|
unsafe fn create<T>(base: *mutable T, len: uint) -> t<T> {
|
||||||
ret t({base: base,
|
ret t({base: base,
|
||||||
size: size,
|
len: len,
|
||||||
rsrc: @dtor_res(option::none)
|
rsrc: @dtor_res(option::none)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -77,20 +77,20 @@ unsafe fn create<T>(base: *mutable T, size: uint) -> t<T> {
|
|||||||
/*
|
/*
|
||||||
Function: create_with_dtor
|
Function: create_with_dtor
|
||||||
|
|
||||||
Create a c_vec::t from a native buffer, with a given size,
|
Create a c_vec::t from a native buffer, with a given length,
|
||||||
and a function to run upon destruction.
|
and a function to run upon destruction.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
|
||||||
base - A native pointer to a buffer
|
base - A native pointer to a buffer
|
||||||
size - The number of elements in the buffer
|
len - The number of elements in the buffer
|
||||||
dtor - A function to run when the value is destructed, useful
|
dtor - A function to run when the value is destructed, useful
|
||||||
for freeing the buffer, etc.
|
for freeing the buffer, etc.
|
||||||
*/
|
*/
|
||||||
unsafe fn create_with_dtor<T>(base: *mutable T, size: uint, dtor: fn@())
|
unsafe fn create_with_dtor<T>(base: *mutable T, len: uint, dtor: fn@())
|
||||||
-> t<T> {
|
-> t<T> {
|
||||||
ret t({base: base,
|
ret t({base: base,
|
||||||
size: size,
|
len: len,
|
||||||
rsrc: @dtor_res(option::some(dtor))
|
rsrc: @dtor_res(option::some(dtor))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ Failure:
|
|||||||
If `ofs` is greater or equal to the length of the vector
|
If `ofs` is greater or equal to the length of the vector
|
||||||
*/
|
*/
|
||||||
fn get<T: copy>(t: t<T>, ofs: uint) -> T {
|
fn get<T: copy>(t: t<T>, ofs: uint) -> T {
|
||||||
assert ofs < (*t).size;
|
assert ofs < len(t);
|
||||||
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
|
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ Failure:
|
|||||||
If `ofs` is greater or equal to the length of the vector
|
If `ofs` is greater or equal to the length of the vector
|
||||||
*/
|
*/
|
||||||
fn set<T: copy>(t: t<T>, ofs: uint, v: T) {
|
fn set<T: copy>(t: t<T>, ofs: uint, v: T) {
|
||||||
assert ofs < (*t).size;
|
assert ofs < len(t);
|
||||||
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
|
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,14 +131,13 @@ fn set<T: copy>(t: t<T>, ofs: uint, v: T) {
|
|||||||
Section: Elimination forms
|
Section: Elimination forms
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// FIXME: Rename to len
|
|
||||||
/*
|
/*
|
||||||
Function: size
|
Function: len
|
||||||
|
|
||||||
Returns the length of the vector
|
Returns the length of the vector
|
||||||
*/
|
*/
|
||||||
fn size<T>(t: t<T>) -> uint {
|
fn len<T>(t: t<T>) -> uint {
|
||||||
ret (*t).size;
|
ret (*t).len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ fn test_basic() {
|
|||||||
set(cv, 4u, 9u8);
|
set(cv, 4u, 9u8);
|
||||||
assert get(cv, 3u) == 8u8;
|
assert get(cv, 3u) == 8u8;
|
||||||
assert get(cv, 4u) == 9u8;
|
assert get(cv, 4u) == 9u8;
|
||||||
assert size(cv) == 16u;
|
assert len(cv) == 16u;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user