Skip to main content

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#![cfg_attr(feature = "unstable_dropck_eyepatch", feature(dropck_eyepatch))]
24
25extern crate alloc;
26#[cfg(feature = "std")]
27extern crate core;
28
29#[cfg(feature = "arc-swap")]
30extern crate arc_swap;
31#[cfg(feature = "serde")]
32extern crate serde;
33#[cfg(feature = "stable_deref_trait")]
34extern crate stable_deref_trait;
35#[cfg(feature = "unsize")]
36extern crate unsize;
37
38mod alloc_error;
39mod arc;
40mod arc_borrow;
41#[cfg(feature = "arc-swap")]
42mod arc_swap_support;
43mod arc_union;
44mod header;
45mod iterator_as_exact_size_iterator;
46mod offset_arc;
47mod thin_arc;
48mod unique_arc;
49
50pub use alloc_error::*;
51pub use arc::*;
52pub use arc_borrow::*;
53pub use arc_union::*;
54pub use header::*;
55pub use offset_arc::*;
56pub use thin_arc::*;
57pub use unique_arc::*;
58
59#[cfg(feature = "std")]
60use std::process::abort;
61
62// `no_std`-compatible abort by forcing a panic while already panicking.
63#[cfg(not(feature = "std"))]
64#[cold]
65fn abort() -> ! {
66    struct PanicOnDrop;
67    impl Drop for PanicOnDrop {
68        fn drop(&mut self) {
69            panic!()
70        }
71    }
72    let _double_panicer = PanicOnDrop;
73    panic!();
74}