MCPcopy Create free account
hub / github.com/archlinux/alpm / bytes_to_string

Function bytes_to_string

alpm-mtree/src/path_decoder.rs:149–162  ·  view source on GitHub ↗

Take the UTF-8 byte sequence and parse it into a `String`. # Errors Returns a custom parse error if we encounter an invalid escaped UTF-8 sequence.

(
    input: &mut &str,
    checkpoint: Checkpoint<&str, &str>,
    bytes: Vec<u8>,
)

Source from the content-addressed store, hash-verified

147///
148/// Returns a custom parse error if we encounter an invalid escaped UTF-8 sequence.
149fn bytes_to_string(
150 input: &mut &str,
151 checkpoint: Checkpoint<&str, &str>,
152 bytes: Vec<u8>,
153) -> ModalResult<String> {
154 match String::from_utf8(bytes) {
155 Ok(decoded) => Ok(decoded),
156 Err(_) => {
157 let mut error = ContextError::new();
158 error = error.add_context(input, &checkpoint, StrContext::Label("UTF-8 byte sequence"));
159 Err(ErrMode::Cut(error))
160 }
161 }
162}
163
164#[cfg(test)]
165mod tests {

Callers 1

unicode_charFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected