-
-
Save valarauca/7d4275d7f23972d8f213d2d5d7e1bf1e to your computer and use it in GitHub Desktop.
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
impl<'i, B> FromPercentEncoded<'i> for Cow<'i, B> | |
where | |
B: ToOwned, | |
&'i B: FromPercentEncoded<'i>, | |
<&'i B as FromPercentEncoded<'i>>::StrError: MaybeCannotGrowError, | |
<&'i B as FromPercentEncoded<'i>>::BytesError: MaybeCannotGrowError, | |
B::Owned: FromPercentEncoded<'i>, | |
{ | |
type BytesError = CowError< | |
<B::Owned as FromPercentEncoded<'i>>::BytesError, | |
<&'i B as FromPercentEncoded<'i>>::BytesError, | |
>; | |
type StrError = CowError< | |
<B::Owned as FromPercentEncoded<'i>>::StrError, | |
<&'i B as FromPercentEncoded<'i>>::StrError, | |
>; | |
fn append_str(&mut self, s: &'i str) -> Result<(), Self::StrError> { | |
let owned = match *self { | |
Cow::Owned(ref mut owned) => owned, | |
Cow::Borrowed(ref mut borrowed) => match borrowed.append_str(s) { | |
Ok(()) => return Ok(()), | |
Err(err) if err.cannot_grow() => self.to_mut(), | |
Err(err) => return Err(CowError::BorrowedError(err)), | |
}, | |
}; | |
owned.append_str(s).map_err(CowError::OwnedError) | |
} | |
fn append_bytes(&mut self, b: &'i [u8]) -> Result<(), Self::BytesError> { | |
let owned = match self { | |
Cow::Owned(owned) => owned, | |
Cow::Borrowed(borrowed) => match borrowed.append_bytes(b) { | |
Ok(()) => return Ok(()), | |
Err(err) if err.cannot_grow() => self.to_mut(), | |
Err(err) => return Err(CowError::BorrowedError(err)), | |
}, | |
}; | |
owned.append_bytes(b).map_err(CowError::OwnedError) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment