Parse a single key-value pair
(
s: &str,
)
| 49 | |
| 50 | /// Parse a single key-value pair |
| 51 | fn parse_key_val<T, U>( |
| 52 | s: &str, |
| 53 | ) -> Result<(T, Vec<u8>), Box<dyn std::error::Error + Send + Sync + 'static>> |
| 54 | where |
| 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 | |
| 73 | pub fn decode_hex(s: &str) -> Result<Vec<u8>, core::num::ParseIntError> { |
| 74 | (0..s.len()) |
nothing calls this directly
no test coverage detected