triomphe/
lib.rs

1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! Fork of Arc. This has the following advantages over std::sync::Arc:
12//!
13//! * `triomphe::Arc` doesn't support weak references: we save space by excluding the weak reference count, and we don't do extra read-modify-update operations to handle the possibility of weak references.
14//! * `triomphe::UniqueArc` allows one to construct a temporarily-mutable `Arc` which can be converted to a regular `triomphe::Arc` later
15//! * `triomphe::OffsetArc` can be used transparently from C++ code and is compatible with (and can be converted to/from) `triomphe::Arc`
16//! * `triomphe::ArcBorrow` is functionally similar to `&triomphe::Arc<T>`, however in memory it's simply `&T`. This makes it more flexible for FFI; the source of the borrow need not be an `Arc` pinned on the stack (and can instead be a pointer from C++, or an `OffsetArc`). Additionally, this helps avoid pointer-chasing.
17//! * `triomphe::Arc` has can be constructed for dynamically-sized types via `from_header_and_iter`
18//! * `triomphe::ThinArc` provides thin-pointer `Arc`s to dynamically sized types
19//! * `triomphe::ArcUnion` is union of two `triomphe:Arc`s which fits inside one word of memory
20
21#![allow(missing_docs)]
22#![cfg_attr(not(feature = "std"), no_std)]
23
24extern crate alloc;
25#[cfg(feature = "std")]
26extern crate core;
27
28#[cfg(feature = "arc-swap")]
29extern crate arc_swap;
30#[cfg(feature = "serde")]
31extern crate serde;
32#[cfg(feature = "stable_deref_trait")]
33extern crate stable_deref_trait;
34#[cfg(feature = "unsize")]
35extern crate unsize;
36
37mod arc;
38mod arc_borrow;
39#[cfg(feature = "arc-swap")]
40mod arc_swap_support;
41mod arc_union;
42mod header;
43mod iterator_as_exact_size_iterator;
44mod offset_arc;
45mod thin_arc;
46mod unique_arc;
47
48pub use arc::*;
49pub use arc_borrow::*;
50pub use arc_union::*;
51pub use header::*;
52pub use offset_arc::*;
53pub use thin_arc::*;
54pub use unique_arc::*;
55
56#[cfg(feature = "std")]
57use std::process::abort;
58
59// `no_std`-compatible abort by forcing a panic while already panicking.
60#[cfg(not(feature = "std"))]
61#[cold]
62fn abort() -> ! {
63    struct PanicOnDrop;
64    impl Drop for PanicOnDrop {
65        fn drop(&mut self) {
66            panic!()
67        }
68    }
69    let _double_panicer = PanicOnDrop;
70    panic!();
71}