diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index 097b686de9..b892eeafc3 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -40,7 +40,7 @@ async fn main() { put = put.with_attachment( attachment .split('&') - .map(|pair| pair.as_bytes().split_at(pair.find('=').unwrap_or(0))) + .map(|pair| split_once(pair, '=')) .collect(), ) } @@ -65,6 +65,17 @@ struct Args { common: CommonArgs, } +fn split_once(s: &str, c: char) -> (&[u8], &[u8]) { + let s_bytes = s.as_bytes(); + match s.find(c) { + Some(index) => { + let (l, r) = s_bytes.split_at(index); + (l, &r[1..]) + } + None => (s_bytes, &[]), + } +} + fn parse_args() -> (Config, KeyExpr<'static>, String, Option) { let args = Args::parse(); (args.common.into(), args.key, args.value, args.attach)