Skip to content

Commit 339618a

Browse files
committed
convert io wrapper records into structs
1 parent 9b17e7a commit 339618a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/libcore/io.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,15 @@ impl *libc::FILE: Reader {
455455
}
456456
}
457457

458+
struct Wrapper<T, C> {
459+
base: T,
460+
cleanup: C,
461+
}
462+
458463
// A forwarding impl of reader that also holds on to a resource for the
459464
// duration of its lifetime.
460465
// FIXME there really should be a better way to do this // #2004
461-
impl<T: Reader, C> {base: T, cleanup: C}: Reader {
466+
impl<R: Reader, C> Wrapper<R, C>: Reader {
462467
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
463468
self.base.read(bytes, len)
464469
}
@@ -487,7 +492,7 @@ pub fn FILERes(f: *libc::FILE) -> FILERes {
487492

488493
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
489494
if cleanup {
490-
{base: f, cleanup: FILERes(f)} as Reader
495+
Wrapper { base: f, cleanup: FILERes(f) } as Reader
491496
} else {
492497
f as Reader
493498
}
@@ -587,7 +592,7 @@ pub trait Writer {
587592
fn get_type(&self) -> WriterType;
588593
}
589594
590-
impl<T: Writer, C> {base: T, cleanup: C}: Writer {
595+
impl<W: Writer, C> Wrapper<W, C>: Writer {
591596
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
592597
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
593598
fn tell(&self) -> uint { self.base.tell() }
@@ -639,7 +644,7 @@ impl *libc::FILE: Writer {
639644

640645
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
641646
if cleanup {
642-
{base: f, cleanup: FILERes(f)} as Writer
647+
Wrapper { base: f, cleanup: FILERes(f) } as Writer
643648
} else {
644649
f as Writer
645650
}
@@ -696,7 +701,7 @@ pub fn FdRes(fd: fd_t) -> FdRes {
696701

697702
pub fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
698703
if cleanup {
699-
{base: fd, cleanup: FdRes(fd)} as Writer
704+
Wrapper { base: fd, cleanup: FdRes(fd) } as Writer
700705
} else {
701706
fd as Writer
702707
}

0 commit comments

Comments
 (0)