@@ -17,7 +17,6 @@ type fd_t = c_int;
17
17
18
18
#[ abi = "cdecl" ]
19
19
extern mod rustrt {
20
- #[ legacy_exports] ;
21
20
fn rust_get_stdin ( ) -> * libc:: FILE ;
22
21
fn rust_get_stdout ( ) -> * libc:: FILE ;
23
22
fn rust_get_stderr ( ) -> * libc:: FILE ;
@@ -27,11 +26,11 @@ extern mod rustrt {
27
26
28
27
// FIXME (#2004): This is all buffered. We might need an unbuffered variant
29
28
// as well
30
- enum SeekStyle { SeekSet , SeekEnd , SeekCur , }
29
+ pub enum SeekStyle { SeekSet , SeekEnd , SeekCur , }
31
30
32
31
33
32
// The raw underlying reader trait. All readers must implement this.
34
- trait Reader {
33
+ pub trait Reader {
35
34
// FIXME (#2004): Seekable really should be orthogonal.
36
35
37
36
// FIXME (#2982): This should probably return an error.
@@ -45,7 +44,7 @@ trait Reader {
45
44
46
45
// Generic utility functions defined on readers
47
46
48
- trait ReaderUtil {
47
+ pub trait ReaderUtil {
49
48
fn read_bytes ( len : uint ) -> ~[ u8 ] ;
50
49
fn read_line ( ) -> ~str ;
51
50
@@ -267,7 +266,7 @@ fn FILERes(f: *libc::FILE) -> FILERes {
267
266
}
268
267
}
269
268
270
- fn FILE_reader ( f : * libc:: FILE , cleanup : bool ) -> Reader {
269
+ pub fn FILE_reader ( f : * libc:: FILE , cleanup : bool ) -> Reader {
271
270
if cleanup {
272
271
{ base: f, cleanup: FILERes ( f) } as Reader
273
272
} else {
@@ -279,9 +278,9 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
279
278
// top-level functions that take a reader, or a set of default methods on
280
279
// reader (which can then be called reader)
281
280
282
- fn stdin ( ) -> Reader { rustrt:: rust_get_stdin ( ) as Reader }
281
+ pub fn stdin ( ) -> Reader { rustrt:: rust_get_stdin ( ) as Reader }
283
282
284
- fn file_reader ( path : & Path ) -> Result < Reader , ~str > {
283
+ pub fn file_reader ( path : & Path ) -> Result < Reader , ~str > {
285
284
let f = os:: as_c_charp ( path. to_str ( ) , |pathbuf| {
286
285
os:: as_c_charp ( "r" , |modebuf|
287
286
libc:: fopen ( pathbuf, modebuf)
@@ -297,7 +296,7 @@ fn file_reader(path: &Path) -> Result<Reader, ~str> {
297
296
298
297
// Byte buffer readers
299
298
300
- type ByteBuf = {buf: &[const u8], mut pos: uint};
299
+ pub type ByteBuf = {buf: &[const u8], mut pos: uint};
301
300
302
301
impl ByteBuf: Reader {
303
302
fn read(buf: &[mut u8], len: uint) -> uint {
@@ -326,21 +325,21 @@ impl ByteBuf: Reader {
326
325
fn tell ( ) -> uint { self . pos }
327
326
}
328
327
329
- fn with_bytes_reader < t > ( bytes : & [ u8 ] , f : fn ( Reader ) -> t ) -> t {
328
+ pub fn with_bytes_reader < t > ( bytes : & [ u8 ] , f : fn ( Reader ) -> t ) -> t {
330
329
f ( { buf: bytes, mut pos: 0 u} as Reader )
331
330
}
332
331
333
- fn with_str_reader < T > ( s : & str , f : fn ( Reader ) -> T ) -> T {
332
+ pub fn with_str_reader < T > ( s : & str , f : fn ( Reader ) -> T ) -> T {
334
333
str:: byte_slice ( s, |bytes| with_bytes_reader ( bytes, f) )
335
334
}
336
335
337
336
// Writing
338
- enum FileFlag { Append , Create , Truncate , NoFlag , }
337
+ pub enum FileFlag { Append , Create , Truncate , NoFlag , }
339
338
340
339
// What type of writer are we?
341
- enum WriterType { Screen , File }
340
+ pub enum WriterType { Screen , File }
342
341
343
- impl WriterType : Eq {
342
+ pub impl WriterType : Eq {
344
343
pure fn eq ( other : & WriterType ) -> bool {
345
344
match ( self , ( * other) ) {
346
345
( Screen , Screen ) | ( File , File ) => true ,
@@ -352,7 +351,7 @@ impl WriterType : Eq {
352
351
353
352
// FIXME (#2004): Seekable really should be orthogonal.
354
353
// FIXME (#2004): eventually u64
355
- trait Writer {
354
+ pub trait Writer {
356
355
fn write ( v : & [ const u8 ] ) ;
357
356
fn seek ( int , SeekStyle ) ;
358
357
fn tell ( ) -> uint ;
@@ -393,7 +392,7 @@ impl *libc::FILE: Writer {
393
392
}
394
393
}
395
394
396
- fn FILE_writer ( f : * libc:: FILE , cleanup : bool ) -> Writer {
395
+ pub fn FILE_writer ( f : * libc:: FILE , cleanup : bool ) -> Writer {
397
396
if cleanup {
398
397
{ base: f, cleanup: FILERes ( f) } as Writer
399
398
} else {
@@ -442,7 +441,7 @@ fn FdRes(fd: fd_t) -> FdRes {
442
441
}
443
442
}
444
443
445
- fn fd_writer ( fd : fd_t , cleanup : bool ) -> Writer {
444
+ pub fn fd_writer ( fd : fd_t , cleanup : bool ) -> Writer {
446
445
if cleanup {
447
446
{ base: fd, cleanup: FdRes ( fd) } as Writer
448
447
} else {
@@ -451,7 +450,7 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
451
450
}
452
451
453
452
454
- fn mk_file_writer ( path : & Path , flags : & [ FileFlag ] )
453
+ pub fn mk_file_writer ( path : & Path , flags : & [ FileFlag ] )
455
454
-> Result < Writer , ~str > {
456
455
457
456
#[ cfg( windows) ]
@@ -481,7 +480,8 @@ fn mk_file_writer(path: &Path, flags: &[FileFlag])
481
480
}
482
481
}
483
482
484
- fn u64_to_le_bytes < T > ( n : u64 , size : uint , f : fn ( v : & [ u8 ] ) -> T ) -> T {
483
+ pub fn u64_to_le_bytes < T > ( n : u64 , size : uint ,
484
+ f : fn ( v : & [ u8 ] ) -> T ) -> T {
485
485
assert size <= 8 u;
486
486
match size {
487
487
1 u => f ( & [ n as u8 ] ) ,
@@ -512,7 +512,8 @@ fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
512
512
}
513
513
}
514
514
515
- fn u64_to_be_bytes < T > ( n : u64 , size : uint , f : fn ( v : & [ u8 ] ) -> T ) -> T {
515
+ pub fn u64_to_be_bytes < T > ( n : u64 , size : uint ,
516
+ f : fn ( v : & [ u8 ] ) -> T ) -> T {
516
517
assert size <= 8 u;
517
518
match size {
518
519
1 u => f ( & [ n as u8 ] ) ,
@@ -543,7 +544,8 @@ fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
543
544
}
544
545
}
545
546
546
- fn u64_from_be_bytes ( data : & [ const u8 ] , start : uint , size : uint ) -> u64 {
547
+ pub fn u64_from_be_bytes ( data : & [ const u8 ] ,
548
+ start : uint , size : uint ) -> u64 {
547
549
let mut sz = size;
548
550
assert ( sz <= 8 u) ;
549
551
let mut val = 0_u64 ;
@@ -558,7 +560,7 @@ fn u64_from_be_bytes(data: &[const u8], start: uint, size: uint) -> u64 {
558
560
559
561
// FIXME: #3048 combine trait+impl (or just move these to
560
562
// default methods on writer)
561
- trait WriterUtil {
563
+ pub trait WriterUtil {
562
564
fn write_char ( ch : char ) ;
563
565
fn write_str ( s : & str ) ;
564
566
fn write_line ( s : & str ) ;
@@ -655,13 +657,13 @@ impl<T: Writer> T : WriterUtil {
655
657
}
656
658
657
659
#[ allow( non_implicitly_copyable_typarams) ]
658
- fn file_writer ( path : & Path , flags : & [ FileFlag ] ) -> Result < Writer , ~str > {
660
+ pub fn file_writer ( path : & Path , flags : & [ FileFlag ] ) -> Result < Writer , ~str > {
659
661
mk_file_writer ( path, flags) . chain ( |w| result:: Ok ( w) )
660
662
}
661
663
662
664
663
665
// FIXME: fileflags // #2004
664
- fn buffered_file_writer ( path : & Path ) -> Result < Writer , ~str > {
666
+ pub fn buffered_file_writer ( path : & Path ) -> Result < Writer , ~str > {
665
667
let f = do os:: as_c_charp ( path. to_str ( ) ) |pathbuf| {
666
668
do os:: as_c_charp ( "w" ) |modebuf| {
667
669
libc:: fopen ( pathbuf, modebuf)
@@ -675,13 +677,13 @@ fn buffered_file_writer(path: &Path) -> Result<Writer, ~str> {
675
677
// FIXME (#2004) it would be great if this could be a const
676
678
// FIXME (#2004) why are these different from the way stdin() is
677
679
// implemented?
678
- fn stdout() -> Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
679
- fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
680
+ pub fn stdout() -> Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
681
+ pub fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
680
682
681
- fn print(s: &str) { stdout().write_str(s); }
682
- fn println(s: &str) { stdout().write_line(s); }
683
+ pub fn print(s: &str) { stdout().write_str(s); }
684
+ pub fn println(s: &str) { stdout().write_line(s); }
683
685
684
- struct BytesWriter {
686
+ pub struct BytesWriter {
685
687
buf: DVec<u8>,
686
688
mut pos: uint,
687
689
}
@@ -725,17 +727,17 @@ impl @BytesWriter : Writer {
725
727
fn get_type() -> WriterType { (*self).get_type() }
726
728
}
727
729
728
- fn BytesWriter() -> BytesWriter {
730
+ pub fn BytesWriter() -> BytesWriter {
729
731
BytesWriter { buf: DVec(), mut pos: 0u }
730
732
}
731
733
732
- fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
734
+ pub fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
733
735
let wr = @BytesWriter();
734
736
f(wr as Writer);
735
737
wr.buf.check_out(|buf| buf)
736
738
}
737
739
738
- fn with_str_writer(f: fn(Writer)) -> ~str {
740
+ pub fn with_str_writer(f: fn(Writer)) -> ~str {
739
741
let mut v = with_bytes_writer(f);
740
742
741
743
// Make sure the vector has a trailing null and is proper utf8.
@@ -746,7 +748,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str {
746
748
}
747
749
748
750
// Utility functions
749
- fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
751
+ pub fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
750
752
uint {
751
753
let mut bpos = pos as int;
752
754
let blen = len as int;
@@ -760,7 +762,7 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
760
762
}
761
763
762
764
#[allow(non_implicitly_copyable_typarams)]
763
- fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
765
+ pub fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
764
766
result::chain(read_whole_file(file), |bytes| {
765
767
if str::is_utf8(bytes) {
766
768
result::Ok(str::from_bytes(bytes))
@@ -773,18 +775,17 @@ fn read_whole_file_str(file: &Path) -> Result<~str, ~str> {
773
775
// FIXME (#2004): implement this in a low-level way. Going through the
774
776
// abstractions is pointless.
775
777
#[ allow( non_implicitly_copyable_typarams) ]
776
- fn read_whole_file ( file : & Path ) -> Result < ~[ u8 ] , ~str > {
778
+ pub fn read_whole_file ( file : & Path ) -> Result < ~[ u8 ] , ~str > {
777
779
result:: chain ( file_reader ( file) , |rdr| {
778
780
result:: Ok ( rdr. read_whole_stream ( ) )
779
781
} )
780
782
}
781
783
782
784
// fsync related
783
785
784
- mod fsync {
785
- #[ legacy_exports] ;
786
+ pub mod fsync {
786
787
787
- enum Level {
788
+ pub enum Level {
788
789
// whatever fsync does on that platform
789
790
FSync ,
790
791
@@ -799,7 +800,7 @@ mod fsync {
799
800
800
801
801
802
// Artifacts that need to fsync on destruction
802
- struct Res < t : Copy > {
803
+ pub struct Res < t : Copy > {
803
804
arg : Arg < t > ,
804
805
drop {
805
806
match self . arg. opt_level {
@@ -812,13 +813,13 @@ mod fsync {
812
813
}
813
814
}
814
815
815
- fn Res <t: Copy > ( +arg: Arg <t>) -> Res <t>{
816
+ pub fn Res <t: Copy > ( +arg: Arg <t>) -> Res <t>{
816
817
Res {
817
818
arg : move arg
818
819
}
819
820
}
820
821
821
- type Arg <t> = {
822
+ pub type Arg < t > = {
822
823
val: t,
823
824
opt_level: Option <Level >,
824
825
fsync_fn: fn @( +f: t, Level ) -> int
@@ -827,8 +828,8 @@ mod fsync {
827
828
// fsync file after executing blk
828
829
// FIXME (#2004) find better way to create resources within lifetime of
829
830
// outer res
830
- fn FILE_res_sync ( file: & FILERes , opt_level: Option <Level >,
831
- blk: fn ( +v: Res <* libc:: FILE >) ) {
831
+ pub fn FILE_res_sync ( file : & FILERes , opt_level : Option < Level > ,
832
+ blk : fn ( +v : Res < * libc:: FILE > ) ) {
832
833
blk ( move Res ( {
833
834
val: file. f , opt_level: opt_level,
834
835
fsync_fn: fn @( +file: * libc:: FILE , l: Level ) -> int {
@@ -838,8 +839,8 @@ mod fsync {
838
839
}
839
840
840
841
// fsync fd after executing blk
841
- fn fd_res_sync ( fd : & FdRes , opt_level : Option < Level > ,
842
- blk : fn ( +v : Res < fd_t > ) ) {
842
+ pub fn fd_res_sync ( fd : & FdRes , opt_level : Option < Level > ,
843
+ blk : fn ( +v : Res < fd_t > ) ) {
843
844
blk ( move Res ( {
844
845
val: fd. fd , opt_level: opt_level,
845
846
fsync_fn: fn @( +fd: fd_t, l: Level ) -> int {
@@ -849,11 +850,11 @@ mod fsync {
849
850
}
850
851
851
852
// Type of objects that may want to fsync
852
- trait FSyncable { fn fsync ( l : Level ) -> int ; }
853
+ pub trait FSyncable { fn fsync ( l : Level ) -> int ; }
853
854
854
855
// Call o.fsync after executing blk
855
- fn obj_sync ( +o : FSyncable , opt_level : Option < Level > ,
856
- blk : fn ( +v : Res < FSyncable > ) ) {
856
+ pub fn obj_sync ( +o : FSyncable , opt_level : Option < Level > ,
857
+ blk : fn ( +v : Res < FSyncable > ) ) {
857
858
blk ( Res ( {
858
859
val: o, opt_level: opt_level,
859
860
fsync_fn: fn @( +o: FSyncable , l: Level ) -> int {
@@ -865,7 +866,6 @@ mod fsync {
865
866
866
867
#[ cfg( test) ]
867
868
mod tests {
868
- #[ legacy_exports] ;
869
869
870
870
#[ test]
871
871
fn test_simple ( ) {
0 commit comments