[][src]Macro slimweb::implwrite

macro_rules! implwrite {
    ($name:ident, ($($(#[cfg($cfg:ident = $val:tt)])? $op:ident $(.$ex:ident())?),*)) => { ... };
    ($name:ident, $life:lifetime, ($($(#[cfg($cfg:ident = $val:tt)])? $op:ident $(.$ex:ident())?),*)) => { ... };
}

Generic impl Write macro.

Example:

This example is not tested
implwrite!(Stream, (Http .get_mut(), #[cfg(feature = "tls")] Https .get_mut()));

Becomes:

This example is not tested
impl Write for Stream {
	fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
		match self {
			Stream::Http(s) => s.get_mut().write(buf),
			#[cfg(feature = "tls")] Stream::Https(s) => s.get_mut().write(buf),
		}
	}

	fn flush(&mut self) -> IoResult<()> {
		match self {
			Stream::Http(s) => s.get_mut().flush(),
			#[cfg(feature = "tls")] Stream::Https(s) => s.get_mut().flush(),
		}
	}
}