Skip to content

Commit

Permalink
Merge pull request #631 from ZettaScaleLabs/fix-attachment-sample
Browse files Browse the repository at this point in the history
Fix z_pub sample attachment string parsing
  • Loading branch information
p-avital authored Dec 18, 2023
2 parents 780ec60 + 2eb4d07 commit e8607a8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion examples/examples/z_pub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand All @@ -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<String>) {
let args = Args::parse();
(args.common.into(), args.key, args.value, args.attach)
Expand Down

0 comments on commit e8607a8

Please sign in to comment.