From 4aab56dc018993e33acc370e90b848e2264c2c5b Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 9 Feb 2025 21:47:14 +0000 Subject: [PATCH] docs: update changelog --- actix-http/CHANGES.md | 1 + actix-http/src/extensions.rs | 14 ++++++++++---- actix-web/CHANGES.md | 1 - 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 982add26a..23ebe43e1 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -5,6 +5,7 @@ ### Added - Add `header::CLEAR_SITE_DATA` constant. +- Add `Extensions::get_or_insert[_with]()` methods. ### Changed diff --git a/actix-http/src/extensions.rs b/actix-http/src/extensions.rs index 7e44492c6..a7736572c 100644 --- a/actix-http/src/extensions.rs +++ b/actix-http/src/extensions.rs @@ -104,14 +104,17 @@ impl Extensions { .and_then(|boxed| boxed.downcast_mut()) } - /// Get a mutable reference or insert an item of a given type. + /// Inserts the given `value` into the extensions if it is not present, then returns a reference + /// to the value in the extensions. /// /// ``` - /// use actix_http::Extensions; + /// # use actix_http::Extensions; /// let mut map = Extensions::new(); /// assert_eq!(map.get::>(), None); + /// /// map.get_or_insert(Vec::::new()).push(1); /// assert_eq!(map.get::>(), Some(&vec![1])); + /// /// map.get_or_insert(Vec::::new()).push(2); /// assert_eq!(map.get::>(), Some(&vec![1,2])); /// ``` @@ -123,14 +126,17 @@ impl Extensions { .expect("extensions map to always contain value T") } - /// Get a mutable reference or insert an item of a given type calculated with the closure given. + /// Inserts a value computed from `f` into the extensions if the given `value` is not present, + /// then returns a reference to the value in the extensions. /// /// ``` - /// use actix_http::Extensions; + /// # use actix_http::Extensions; /// let mut map = Extensions::new(); /// assert_eq!(map.get::>(), None); + /// /// map.get_or_insert_with(Vec::::new).push(1); /// assert_eq!(map.get::>(), Some(&vec![1])); + /// /// map.get_or_insert_with(Vec::::new).push(2); /// assert_eq!(map.get::>(), Some(&vec![1,2])); /// ``` diff --git a/actix-web/CHANGES.md b/actix-web/CHANGES.md index 65be2b787..edbdc6982 100644 --- a/actix-web/CHANGES.md +++ b/actix-web/CHANGES.md @@ -6,7 +6,6 @@ - On Windows, an error is now returned from `HttpServer::bind()` (or TLS variants) when binding to a socket that's already in use. - Update `brotli` dependency to `7`. - Minimum supported Rust version (MSRV) is now 1.75. -- Added `Extensions::get_or_insert` and `Extensions::get_or_insert_with` ## 4.9.0