Skip to content

Instantly share code, notes, and snippets.

@reem
Created June 19, 2014 00:53
Show Gist options
  • Save reem/e6ceeae1eeeb101730f7 to your computer and use it in GitHub Desktop.
Save reem/e6ceeae1eeeb101730f7 to your computer and use it in GitHub Desktop.
Borrowing
let isAbsoluteUri = match req.request_uri {
AbsolutePath(_) => true,
_ => false
};
if isAbsoluteUri {
match req.request_uri {
AbsolutePath(ref mut path) => {
*path = path.as_slice().slice_from(self.route.len()).to_string();
},
// Absolutely cannot happen because of our previous check.
_ => fail!()
} // Previous borrow of req ends here.
// So we can borrow it again here.
self.iron.furnace.forge(req, res, Some(alloy));
// And repair the damage here, for future middleware
match req.request_uri {
AbsolutePath(ref mut path) => {
*path = self.route.clone().append(path.as_slice());
},
// Absolutely cannot happen because of our previous check.
_ => fail!()
} // Previous borrow of req ends here.
Unwind
} else {
Continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment