boar/
lib.rs

1/*!
2This crate provides flexible clone on write smart pointers
3with Borrowed, Owned, Arc, Rc and Static variants.
4They are like std's [`Cow`][std::borrow::Cow]
5but with additonal [`Arc`][std::sync::Arc], [`Rc`][std::rc::Rc]
6and `Static` variants.
7Unlike std's [`Cow`][std::borrow::Cow],
8they can also be used with types
9that don't implement [`Clone`] or [`ToOwned`].
10
11The `boar` smart pointers allow you to:
12
13- share data efficiently
14- decide ownership at runtime
15- avoid cloning the data until it becomes necessary
16
17# Examples
18
19```rust
20# fn main() -> std::io::Result<()> {
21use std::sync::Arc;
22use boar::BoasStr;
23
24// No need to allocate memory for a &'static str
25let title = BoasStr::Static("Dune");
26
27// Also no need to allocate memory for a &str, that's valid for the required scope
28let title = read_file("title.txt")?;
29let title = BoasStr::Borrowed(&title);
30
31// The author's name shouldn't be too long.
32// So we can just store it in a normal String.
33let author = BoasStr::Owned(read_file("dune/author.txt")?);
34
35// A whole book is really long.
36// And we want to share this string with multiple threads.
37// So it would be efficient to store in an Arc,
38// since cloning the Arc does not clone the String data inside of it.
39let book_text = BoasStr::Arc(Arc::new(read_file("dune/book.txt")?));
40
41// We can store a &str, String and Arc<String> inside the same Vec
42// because we are using the BoasStr enum.
43let book_infos: Vec<BoasStr> = Vec::from([title, author, book_text]);
44
45fn read_file(path: &str) -> std::io::Result<String> {
46    // ...
47# Ok(String::new())
48}
49# Ok(()) }
50```
51*/
52#![forbid(unsafe_code)]
53
54mod boa;
55mod boar;
56mod boars;
57mod boas;
58
59pub use self::boa::{Boa, BoaBox, BoaTo, BoaVec};
60pub use self::boar::{Boar, BoarBox, BoarTo, BoarVec};
61pub use self::boars::{Boars, BoarsBox, BoarsStr, BoarsTo, BoarsVec};
62pub use self::boas::{Boas, BoasBox, BoasStr, BoasTo, BoasVec};