From 04e6e1c362389faa806d601f6cc3366d78af01de Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Wed, 14 May 2025 20:29:06 +0200 Subject: [PATCH 1/2] Add Default impl --- arcshift/CHANGELOG.md | 3 +++ arcshift/Cargo.toml | 2 +- arcshift/src/cell.rs | 3 +-- arcshift/src/lib.rs | 9 ++++++++- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 arcshift/CHANGELOG.md diff --git a/arcshift/CHANGELOG.md b/arcshift/CHANGELOG.md new file mode 100644 index 0000000..6763eaa --- /dev/null +++ b/arcshift/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.4.0 + +`ArcShift` now implements `Default` if `T:Default`. diff --git a/arcshift/Cargo.toml b/arcshift/Cargo.toml index d9969da..46bc23c 100644 --- a/arcshift/Cargo.toml +++ b/arcshift/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arcshift" -version = "0.3.1" +version = "0.4.0" documentation = "https://docs.rs/arcshift/" homepage = "https://github.com/avl/arcshift/" repository = "https://github.com/avl/arcshift/" diff --git a/arcshift/src/cell.rs b/arcshift/src/cell.rs index a8ecf64..843599f 100644 --- a/arcshift/src/cell.rs +++ b/arcshift/src/cell.rs @@ -12,8 +12,7 @@ use core::ops::Deref; /// a non-threadsafe `ArcShiftCellHandle`. This handle implements Deref, giving access /// to the pointed to &T. This handle should not be leaked, /// but if it is leaked, the effect is that whatever value the ArcShiftCell-instance -/// pointed to at that time, will forever leak also. All the linked-list nodes from -/// that entry and onward will also leak. So make sure to not leak the handle! +/// pointed to at that time, will forever leak also. pub struct ArcShiftCell { // UnsafeCell makes ArcShiftCell invariant, which it needs to be inner: UnsafeCell>, diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index d3822ff..98c2d25 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -71,7 +71,8 @@ //! inner value). ArcShift can still be used with only shared access ([`ArcShift::shared_get`]), //! and performance is still very good as long as the pointer is current. However, if //! the ArcShift instance is stale (needs reloading, because an update has occurred), reads will -//! be approximately twice as costly as for RwLock. +//! be approximately twice as costly as for RwLock. One mitigation for this is to use +//! [`cell::ArcShiftCell`]. However, this type is not `Sync`, only `Send`. //! * When modifying the value, the old version of the value lingers in memory until //! the last ArcShift that uses it has reloaded. Such a reload only happens when the ArcShift //! is accessed using a unique (`&mut`) access (like [`ArcShift::get`] or [`ArcShift::reload`]). @@ -416,6 +417,12 @@ where } } +impl Default for ArcShift { + fn default() -> Self { + ArcShift::new(Default::default()) + } +} + impl Debug for ArcShiftWeak where T: Debug, From 06fb70e3f066278f973338f1700d60eb0aba06c1 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Mon, 9 Jun 2025 22:11:30 +0200 Subject: [PATCH 2/2] Silence warnings on latest nightly --- arcshift/src/cell.rs | 2 +- arcshift/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arcshift/src/cell.rs b/arcshift/src/cell.rs index 843599f..cf9b4c1 100644 --- a/arcshift/src/cell.rs +++ b/arcshift/src/cell.rs @@ -130,7 +130,7 @@ impl ArcShiftCell { /// [`ArcShiftCellHandle`]. Leaking the handle will leak resources, but /// not cause undefined behaviour. #[inline] - pub fn borrow(&self) -> ArcShiftCellHandle { + pub fn borrow(&self) -> ArcShiftCellHandle<'_, T> { self.recursion.set(self.recursion.get() + 1); ArcShiftCellHandle { cell: self, diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 98c2d25..962c0cf 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -417,7 +417,7 @@ where } } -impl Default for ArcShift { +impl Default for ArcShift { fn default() -> Self { ArcShift::new(Default::default()) } @@ -3245,7 +3245,7 @@ impl ArcShift { /// This method has the advantage that it doesn't require `&mut self` access, /// but is otherwise inferior to [`ArcShift::get`]. #[inline(always)] - pub fn shared_get(&self) -> SharedGetGuard { + pub fn shared_get(&self) -> SharedGetGuard<'_, T> { if is_sized::() { let ptr = from_dummy::(self.item.as_ptr()); // SAFETY: