Skip to content

Instantly share code, notes, and snippets.

View panicbit's full-sized avatar
:shipit:
Ship it

panicbit

:shipit:
Ship it
  • Dortmund, Germany, ᐰ
View GitHub Profile
use std::io::{self,Read};
use std::borrow::Borrow;
use iron::response::{WriteBody,ResponseBody};
pub struct BodyChain<T, U>(pub T, pub U);
impl <T: WriteBody, U: WriteBody> WriteBody for BodyChain<T, U> {
fn write_body(&mut self, res: &mut ResponseBody) -> io::Result<()> {
let &mut BodyChain(ref mut a, ref mut b) = self;
a.write_body(res).and_then(|_| b.write_body(res))
// Instead of this fuss:
let prefix = Cursor::new("foo".to_owned().into_bytes());
let data = Cursor::new((...).into_bytes()); // Some big Vec/String
let body: Box<Read + Send> = Box::new(prefix.chain(data));
// We can now just write:
let prefix = "foo";
let data = ...; // Some big Vec/String
let mut request = ...;
match request.dispatch() {
// On auth errors, dispatch request again
Err(RequestError::Auth) => request.dispatch(),
// Ignore other errors
request => request
};
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/include/llvm/Support/Casting.h:237: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::PointerType; Y = llvm::Type; typename llvm::cast_retty<X, Y*>::ret_type = llvm::PointerType*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.