(code: &str)
| 89 | } |
| 90 | |
| 91 | pub fn from_str(code: &str) -> Encoding { |
| 92 | if code.len() > CODE_INLINE_CAP { |
| 93 | Encoding { code: Code::Owned(code.to_owned()) } |
| 94 | } else { |
| 95 | let mut bytes = [0; CODE_INLINE_CAP]; |
| 96 | for (dst, byte) in bytes.iter_mut().zip(code.bytes()) { |
| 97 | *dst = byte; |
| 98 | } |
| 99 | Encoding { code: Code::Inline(code.len() as u8, bytes) } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | pub unsafe fn from_malloc_str(ptr: *mut c_char) -> Encoding { |
| 104 | let s = CStr::from_ptr(ptr); |
no outgoing calls