Debian Codegraph @

debian/rust-vendor/jiff/src/util/sync.rs

raw
1 /*!
2 This module re-exports `Arc`.
3
4 That is, it provides some indirection for the case when `alloc::sync::Arc` is
5 unavailable.
6
7 It also defines a "dumb" `Arc` in core-only mode that doesn't actually do
8 anything (no indirection, no reference counting).
9 */
10
11 #[cfg(all(feature = "alloc", not(target_has_atomic = "ptr")))]
12 pub(crate) use portable_atomic_util::Arc;
13
14 #[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
15 pub(crate) use alloc::sync::Arc;
16
17 /// A "fake" `Arc`.
18 ///
19 /// Basically, it exposes the `Arc` APIs we use in Jiff, but doesn't
20 /// actually introduce indirection or reference counting. It's only used
21 /// in core-only mode and in effect results in inlining all data into its
22 /// container.
23 ///
24 /// Not ideal, but we use `Arc` in very few places. One is `TimeZone`,
25 /// which ends up being pretty small in core-only mode since it doesn't
26 /// support carrying TZif data.
27 #[cfg(not(feature = "alloc"))]
28 #[derive(Clone, Debug, Eq, PartialEq)]
29 pub(crate) struct Arc<T>(T);
30
31 #[cfg(not(feature = "alloc"))]
32 impl<T> Arc<T> {
33 pub(crate) fn new(t: T) -> Arc<T> {
34 Arc(t)
35 }
36
37 pub(crate) fn get_mut(this: &mut Arc<T>) -> Option<&mut T> {
38 Some(&mut this.0)
39 }
40 }
41
42 #[cfg(not(feature = "alloc"))]
43 impl<T> core::ops::Deref for Arc<T> {
44 type Target = T;
45 fn deref(&self) -> &T {
46 &self.0
47 }
48 }