Skip to main content

lines_example/
lines_example.rs

1// Copyright (c) 2026 CyberNestSticks LLC
2// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
3// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
4// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
5// option. This file may not be copied, modified, or distributed
6// except according to those terms.
7
8// Author: Lawrence (Larry) Foard
9
10use arcstr::literal;
11use zcstring::ZCString;
12
13fn main() {
14    let animals: ZCString = literal!(
15        r#"
16        cats
17        dogs
18        frogs
19    "#
20    )
21    .into();
22
23    animals
24        // wrap an iterator returning method such that it returns
25        // an iterator of ZCStrings
26        .wrap_iter(|s| s.lines())
27        // trim the entry, ZCString::map() converts the resulting
28        // &str to a zero-copy ZCString when possible
29        .map(|l| l.map(|s| s.trim()))
30        // filter empty lines
31        .filter(|l| !l.is_empty())
32        .for_each(|l| println!("{:?} zero-copy: {}", l, animals.source_of(&l)));
33}