This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let mut request = ...; | |
| match request.dispatch() { | |
| // On auth errors, dispatch request again | |
| Err(RequestError::Auth) => request.dispatch(), | |
| // Ignore other errors | |
| request => request | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
NewerOlder