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