Skip to content

Commit 6cfc196

Browse files
committed
libstd: rename c_vec::size to len.
1 parent 3e68803 commit 6cfc196

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/libstd/c_vec.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ taken to ensure that a reference to the c_vec::t is still held if needed.
3131
export t;
3232
export create, create_with_dtor;
3333
export get, set;
34-
export size;
34+
export len;
3535
export ptr;
3636

3737
/*
@@ -43,7 +43,7 @@ export ptr;
4343
*/
4444

4545
tag t<T> {
46-
t({ base: *mutable T, size: uint, rsrc: @dtor_res});
46+
t({ base: *mutable T, len: uint, rsrc: @dtor_res});
4747
}
4848

4949
resource dtor_res(dtor: option::t<fn@()>) {
@@ -60,37 +60,37 @@ resource dtor_res(dtor: option::t<fn@()>) {
6060
/*
6161
Function: create
6262
63-
Create a c_vec::t from a native buffer with a given size.
63+
Create a c_vec::t from a native buffer with a given length.
6464
6565
Parameters:
6666
6767
base - A native pointer to a buffer
68-
size - The number of elements in the buffer
68+
len - The number of elements in the buffer
6969
*/
70-
unsafe fn create<T>(base: *mutable T, size: uint) -> t<T> {
70+
unsafe fn create<T>(base: *mutable T, len: uint) -> t<T> {
7171
ret t({base: base,
72-
size: size,
72+
len: len,
7373
rsrc: @dtor_res(option::none)
7474
});
7575
}
7676

7777
/*
7878
Function: create_with_dtor
7979
80-
Create a c_vec::t from a native buffer, with a given size,
80+
Create a c_vec::t from a native buffer, with a given length,
8181
and a function to run upon destruction.
8282
8383
Parameters:
8484
8585
base - A native pointer to a buffer
86-
size - The number of elements in the buffer
86+
len - The number of elements in the buffer
8787
dtor - A function to run when the value is destructed, useful
8888
for freeing the buffer, etc.
8989
*/
90-
unsafe fn create_with_dtor<T>(base: *mutable T, size: uint, dtor: fn@())
90+
unsafe fn create_with_dtor<T>(base: *mutable T, len: uint, dtor: fn@())
9191
-> t<T> {
9292
ret t({base: base,
93-
size: size,
93+
len: len,
9494
rsrc: @dtor_res(option::some(dtor))
9595
});
9696
}
@@ -109,7 +109,7 @@ Failure:
109109
If `ofs` is greater or equal to the length of the vector
110110
*/
111111
fn get<T: copy>(t: t<T>, ofs: uint) -> T {
112-
assert ofs < (*t).size;
112+
assert ofs < len(t);
113113
ret unsafe { *ptr::mut_offset((*t).base, ofs) };
114114
}
115115

@@ -123,22 +123,21 @@ Failure:
123123
If `ofs` is greater or equal to the length of the vector
124124
*/
125125
fn set<T: copy>(t: t<T>, ofs: uint, v: T) {
126-
assert ofs < (*t).size;
126+
assert ofs < len(t);
127127
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
128128
}
129129

130130
/*
131131
Section: Elimination forms
132132
*/
133133

134-
// FIXME: Rename to len
135134
/*
136-
Function: size
135+
Function: len
137136
138137
Returns the length of the vector
139138
*/
140-
fn size<T>(t: t<T>) -> uint {
141-
ret (*t).size;
139+
fn len<T>(t: t<T>) -> uint {
140+
ret (*t).len;
142141
}
143142

144143
/*

src/test/stdtest/c_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn test_basic() {
2828
set(cv, 4u, 9u8);
2929
assert get(cv, 3u) == 8u8;
3030
assert get(cv, 4u) == 9u8;
31-
assert size(cv) == 16u;
31+
assert len(cv) == 16u;
3232
}
3333

3434
#[test]

0 commit comments

Comments
 (0)