trivial_example/trivial_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 // ZCString creation examples
15 println!("From str: {:?}", ZCString::from("str"));
16 #[cfg(feature = "std")]
17 println!("From String: {:?}", ZCString::from(String::from("str")));
18 println!("New ZCString: {:?}", ZCString::new());
19
20 // how big is a ZCString member in a structure as compared &str?
21
22 // we expect the same size. Why? &str is a fat pointer and
23 // ZString is a Substr which is a thin pointer to an ArcStr plus
24 // a range consisting of two u32s
25 println!("size_of &str: {}", size_of::<&str>());
26 println!("size_of ZCString: {}", size_of::<ZCString>());
27
28 // create a ZCString pointing to a staticly defined &str
29 let zc = ZCString::from(literal!("cats and dogs"));
30
31 // lets make some substrings
32 let s1 = zc.substr(0..4);
33 let s2 = zc.substr(9..12);
34
35 // show the strings and the fact they live in zc
36 println!("s1: {:?} lives in zc? {}", s1, zc.source_of(&s1));
37 println!("s2: {:?} lives in zc? {}", s2, zc.source_of(&s2));
38}