Returns self as a `str`.
(&self)
| 46 | |
| 47 | /// Returns self as a `str`. |
| 48 | pub fn as_str(&self) -> &str { |
| 49 | match self.code { |
| 50 | Code::Slice(code) => code, |
| 51 | Code::Owned(ref code) => code, |
| 52 | Code::Inline(len, ref bytes) => unsafe { |
| 53 | str::from_utf8_unchecked(&bytes[..len as usize]) |
| 54 | }, |
| 55 | Code::Malloc(ref buf) => unsafe { |
| 56 | str::from_utf8_unchecked(&buf[..buf.len() - 1]) |
| 57 | }, |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | impl Clone for Encoding { |