Created
April 29, 2021 03:35
-
-
Save Lucretiel/335821c39f45d864971a13d217d83713 to your computer and use it in GitHub Desktop.
This file contains 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