Serialization Without Crates
Key/Value Parse
Split Serialized Text
Deserialization turns text back into values. For a tiny key/value format, split_once separates the fields safely.
Program
Play the program to choose a raw record and parse it into a key and value.
key_value_parse.rs
fn main() {
let raw = ;
let parsed = parse_pair(raw).unwrap_or(("invalid", ""));
println!("{}:{}", parsed.0, parsed.1);
}
fn parse_pair(text: &str) -> Option<(&str, &str)> {
let (key, value) = text.split_once('=')?;
Some((key, value))
}
fn main() {
let raw = ;
let parsed = parse_pair(raw).unwrap_or(("invalid", ""));
println!("{}:{}", parsed.0, parsed.1);
}
fn parse_pair(text: &str) -> Option<(&str, &str)> {
let (key, value) = text.split_once('=')?;
Some((key, value))
}
fn main() {
let raw = ;
let parsed = parse_pair(raw).unwrap_or(("invalid", ""));
println!("{}:{}", parsed.0, parsed.1);
}
fn parse_pair(text: &str) -> Option<(&str, &str)> {
let (key, value) = text.split_once('=')?;
Some((key, value))
}
deserialization
Deserialization reads structured text back into program values.
split_once
`split_once('=')` returns `None` if the separator is missing.
fallback
`unwrap_or` supplies a controlled fallback for malformed input.