convert io wrapper records into structs
This commit is contained in:
parent
9b17e7a777
commit
339618a7f9
@ -455,10 +455,15 @@ fn tell(&self) -> uint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Wrapper<T, C> {
|
||||||
|
base: T,
|
||||||
|
cleanup: C,
|
||||||
|
}
|
||||||
|
|
||||||
// A forwarding impl of reader that also holds on to a resource for the
|
// A forwarding impl of reader that also holds on to a resource for the
|
||||||
// duration of its lifetime.
|
// duration of its lifetime.
|
||||||
// FIXME there really should be a better way to do this // #2004
|
// FIXME there really should be a better way to do this // #2004
|
||||||
impl<T: Reader, C> {base: T, cleanup: C}: Reader {
|
impl<R: Reader, C> Wrapper<R, C>: Reader {
|
||||||
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
fn read(&self, bytes: &[mut u8], len: uint) -> uint {
|
||||||
self.base.read(bytes, len)
|
self.base.read(bytes, len)
|
||||||
}
|
}
|
||||||
@ -487,7 +492,7 @@ pub fn FILERes(f: *libc::FILE) -> FILERes {
|
|||||||
|
|
||||||
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
|
pub fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
|
||||||
if cleanup {
|
if cleanup {
|
||||||
{base: f, cleanup: FILERes(f)} as Reader
|
Wrapper { base: f, cleanup: FILERes(f) } as Reader
|
||||||
} else {
|
} else {
|
||||||
f as Reader
|
f as Reader
|
||||||
}
|
}
|
||||||
@ -587,7 +592,7 @@ pub trait Writer {
|
|||||||
fn get_type(&self) -> WriterType;
|
fn get_type(&self) -> WriterType;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Writer, C> {base: T, cleanup: C}: Writer {
|
impl<W: Writer, C> Wrapper<W, C>: Writer {
|
||||||
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
|
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
|
||||||
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
|
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
|
||||||
fn tell(&self) -> uint { self.base.tell() }
|
fn tell(&self) -> uint { self.base.tell() }
|
||||||
@ -639,7 +644,7 @@ fn get_type(&self) -> WriterType {
|
|||||||
|
|
||||||
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
|
pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
|
||||||
if cleanup {
|
if cleanup {
|
||||||
{base: f, cleanup: FILERes(f)} as Writer
|
Wrapper { base: f, cleanup: FILERes(f) } as Writer
|
||||||
} else {
|
} else {
|
||||||
f as Writer
|
f as Writer
|
||||||
}
|
}
|
||||||
@ -696,7 +701,7 @@ pub fn FdRes(fd: fd_t) -> FdRes {
|
|||||||
|
|
||||||
pub fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
|
pub fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
|
||||||
if cleanup {
|
if cleanup {
|
||||||
{base: fd, cleanup: FdRes(fd)} as Writer
|
Wrapper { base: fd, cleanup: FdRes(fd) } as Writer
|
||||||
} else {
|
} else {
|
||||||
fd as Writer
|
fd as Writer
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user