From b968c8e6cd362567bf0047a96d261691dfca43e8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 13 Mar 2012 14:39:28 -0700 Subject: Name types after their modules instead of 't' --- src/libstd/c_vec.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/libstd/c_vec.rs') diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 532f2903af3..28ee44690ee 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -25,7 +25,7 @@ form -- for instance, to pass memory back into C -- but great care must be taken to ensure that a reference to the c_vec::t is still held if needed. "]; -export t; +export c_vec; export c_vec, c_vec_with_dtor; export get, set; export len; @@ -37,8 +37,8 @@ The type representing a native chunk of memory Wrapped in a enum for opacity; FIXME #818 when it is possible to have truly opaque types, this should be revisited. "] -enum t { - t({ base: *mutable T, len: uint, rsrc: @dtor_res}) +enum c_vec { + c_vec_({ base: *mutable T, len: uint, rsrc: @dtor_res}) } resource dtor_res(dtor: option) { @@ -53,22 +53,23 @@ resource dtor_res(dtor: option) { */ #[doc = " -Create a c_vec::t from a native buffer with a given length. +Create a `c_vec` from a native buffer with a given length. # Arguments * base - A native pointer to a buffer * len - The number of elements in the buffer "] -unsafe fn c_vec(base: *mutable T, len: uint) -> t { - ret t({base: base, - len: len, - rsrc: @dtor_res(option::none) - }); +unsafe fn c_vec(base: *mutable T, len: uint) -> c_vec { + ret c_vec_({ + base: base, + len: len, + rsrc: @dtor_res(option::none) + }); } #[doc = " -Create a c_vec::t from a native buffer, with a given length, +Create a `c_vec` from a native buffer, with a given length, and a function to run upon destruction. # Arguments @@ -79,11 +80,12 @@ and a function to run upon destruction. for freeing the buffer, etc. "] unsafe fn c_vec_with_dtor(base: *mutable T, len: uint, dtor: fn@()) - -> t { - ret t({base: base, - len: len, - rsrc: @dtor_res(option::some(dtor)) - }); + -> c_vec { + ret c_vec_({ + base: base, + len: len, + rsrc: @dtor_res(option::some(dtor)) + }); } /* @@ -95,7 +97,7 @@ Retrieves an element at a given index Fails if `ofs` is greater or equal to the length of the vector "] -fn get(t: t, ofs: uint) -> T { +fn get(t: c_vec, ofs: uint) -> T { assert ofs < len(t); ret unsafe { *ptr::mut_offset((*t).base, ofs) }; } @@ -105,7 +107,7 @@ Sets the value of an element at a given index Fails if `ofs` is greater or equal to the length of the vector "] -fn set(t: t, ofs: uint, v: T) { +fn set(t: c_vec, ofs: uint, v: T) { assert ofs < len(t); unsafe { *ptr::mut_offset((*t).base, ofs) = v }; } @@ -115,12 +117,12 @@ fn set(t: t, ofs: uint, v: T) { */ #[doc = "Returns the length of the vector"] -fn len(t: t) -> uint { +fn len(t: c_vec) -> uint { ret (*t).len; } #[doc = "Returns a pointer to the first element of the vector"] -unsafe fn ptr(t: t) -> *mutable T { +unsafe fn ptr(t: c_vec) -> *mutable T { ret (*t).base; } @@ -128,7 +130,7 @@ unsafe fn ptr(t: t) -> *mutable T { mod tests { import libc::*; - fn malloc(n: size_t) -> t { + fn malloc(n: size_t) -> c_vec { let mem = libc::malloc(n); assert mem as int != 0; -- cgit 1.4.1-3-g733a5