From 04e6e1c362389faa806d601f6cc3366d78af01de Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Wed, 14 May 2025 20:29:06 +0200 Subject: [PATCH 1/3] 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 392454ac97566cba6e812b247a5ad7145ba4a53e Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Wed, 14 May 2025 20:30:27 +0200 Subject: [PATCH 2/3] fmt --- arcshift/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 98c2d25..7c1f98e 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()) } From 359d5556d63af0e452ed0e5f49f0e6e6322b0920 Mon Sep 17 00:00:00 2001 From: Anders Musikka Date: Wed, 14 May 2025 21:25:44 +0200 Subject: [PATCH 3/3] fix-bound --- arcshift/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 7c1f98e..366037a 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()) }