MCPcopy Create free account
hub / github.com/IBM/ACE-RISCV / parse_key_val

Function parse_key_val

tools/cove_tap_tool/src/main.rs:51–71  ·  view source on GitHub ↗

Parse a single key-value pair

(
    s: &str,
)

Source from the content-addressed store, hash-verified

49
50/// Parse a single key-value pair
51fn parse_key_val<T, U>(
52 s: &str,
53) -> Result<(T, Vec<u8>), Box<dyn std::error::Error + Send + Sync + 'static>>
54where
55 T: std::str::FromStr,
56 T::Err: std::error::Error + Send + Sync + 'static,
57 U: std::str::FromStr,
58 U::Err: std::error::Error + Send + Sync + 'static,
59{
60 let pos = s
61 .find('=')
62 .ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?;
63 let key = s[..pos].parse()?;
64 let value = &s[pos + 1..];
65 let value = if value.starts_with("0x") {
66 decode_hex(&value[2..])?
67 } else {
68 value.as_bytes().to_vec()
69 };
70 Ok((key, value))
71}
72
73pub fn decode_hex(s: &str) -> Result<Vec<u8>, core::num::ParseIntError> {
74 (0..s.len())

Callers

nothing calls this directly

Calls 1

decode_hexFunction · 0.85

Tested by

no test coverage detected