diff --git a/ntex-service/CHANGES.md b/ntex-service/CHANGES.md index c9c81d7c..4a370f81 100644 --- a/ntex-service/CHANGES.md +++ b/ntex-service/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [1.2.0-beta.2] - 2023-06-19 + +* Remove Deref for Container + ## [1.2.0-beta.1] - 2023-06-19 * Rename Ctx to ServiceCtx diff --git a/ntex-service/Cargo.toml b/ntex-service/Cargo.toml index aca254e4..11185e9b 100644 --- a/ntex-service/Cargo.toml +++ b/ntex-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-service" -version = "1.2.0-beta.1" +version = "1.2.0-beta.2" authors = ["ntex contributors "] description = "ntex service" keywords = ["network", "framework", "async", "futures"] diff --git a/ntex-service/src/ctx.rs b/ntex-service/src/ctx.rs index c9c70e65..2bd0fac6 100644 --- a/ntex-service/src/ctx.rs +++ b/ntex-service/src/ctx.rs @@ -1,6 +1,4 @@ -use std::{ - cell::UnsafeCell, future::Future, marker, ops, pin::Pin, rc::Rc, task, task::Poll, -}; +use std::{cell::UnsafeCell, future::Future, marker, pin::Pin, rc::Rc, task, task::Poll}; use crate::{Service, ServiceFactory}; @@ -73,6 +71,11 @@ impl Container { } } + /// Return reference to inner type + pub fn get_ref(&self) -> &S { + self.svc.as_ref() + } + #[inline] /// Returns `Ready` when the service is able to process requests. pub fn poll_ready(&self, cx: &mut task::Context<'_>) -> Poll> @@ -142,15 +145,6 @@ impl From for Container { } } -impl ops::Deref for Container { - type Target = S; - - #[inline] - fn deref(&self) -> &S { - self.svc.as_ref() - } -} - impl<'a, S: ?Sized> ServiceCtx<'a, S> { pub(crate) fn new(waiters: &'a Waiters) -> Self { Self { diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 8de59592..8d4ca7de 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -52,7 +52,7 @@ ntex-codec = "0.6.2" ntex-connect = "0.3.0-beta.1" ntex-http = "0.1.9" ntex-router = "0.5.1" -ntex-service = "1.2.0-beta.1" +ntex-service = "1.2.0-beta.2" ntex-macros = "0.1.3" ntex-util = "0.3.0-beta.1" ntex-bytes = "0.1.19" diff --git a/ntex/src/http/client/pool.rs b/ntex/src/http/client/pool.rs index aa69b279..9b68f9d9 100644 --- a/ntex/src/http/client/pool.rs +++ b/ntex/src/http/client/pool.rs @@ -664,49 +664,49 @@ mod tests { assert_eq!(store.borrow().len(), 1); assert!(format!("{:?}", conn).contains("H1Connection")); assert_eq!(conn.protocol(), HttpProtocol::Http1); - assert_eq!(pool.inner.borrow().acquired, 1); - assert!(pool.inner.borrow().connecting.is_empty()); + assert_eq!(pool.get_ref().inner.borrow().acquired, 1); + assert!(pool.get_ref().inner.borrow().connecting.is_empty()); // pool is full, waiting let mut fut = pool.call(req.clone()); assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending()); - assert_eq!(pool.waiters.borrow().waiters.len(), 1); + assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1); // release connection and push it to next waiter conn.release(false); - assert_eq!(pool.inner.borrow().acquired, 0); + assert_eq!(pool.get_ref().inner.borrow().acquired, 0); let _conn = fut.await.unwrap(); assert_eq!(store.borrow().len(), 1); - assert!(pool.waiters.borrow().waiters.is_empty()); + assert!(pool.get_ref().waiters.borrow().waiters.is_empty()); drop(_conn); // close connnection let conn = pool.call(req.clone()).await.unwrap(); assert_eq!(store.borrow().len(), 2); - assert_eq!(pool.inner.borrow().acquired, 1); - assert!(pool.inner.borrow().connecting.is_empty()); + assert_eq!(pool.get_ref().inner.borrow().acquired, 1); + assert!(pool.get_ref().inner.borrow().connecting.is_empty()); let mut fut = pool.call(req.clone()); assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending()); - assert_eq!(pool.waiters.borrow().waiters.len(), 1); + assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1); // release and close conn.release(true); - assert_eq!(pool.inner.borrow().acquired, 0); - assert!(pool.inner.borrow().connecting.is_empty()); + assert_eq!(pool.get_ref().inner.borrow().acquired, 0); + assert!(pool.get_ref().inner.borrow().connecting.is_empty()); let conn = fut.await.unwrap(); assert_eq!(store.borrow().len(), 3); - assert!(pool.waiters.borrow().waiters.is_empty()); - assert!(pool.inner.borrow().connecting.is_empty()); - assert_eq!(pool.inner.borrow().acquired, 1); + assert!(pool.get_ref().waiters.borrow().waiters.is_empty()); + assert!(pool.get_ref().inner.borrow().connecting.is_empty()); + assert_eq!(pool.get_ref().inner.borrow().acquired, 1); // drop waiter, no interest in connection let mut fut = pool.call(req.clone()); assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending()); drop(fut); sleep(Millis(50)).await; - pool.inner.borrow_mut().check_availibility(); - assert!(pool.waiters.borrow().waiters.is_empty()); + pool.get_ref().inner.borrow_mut().check_availibility(); + assert!(pool.get_ref().waiters.borrow().waiters.is_empty()); // different uri let req = Connect { @@ -715,19 +715,19 @@ mod tests { }; let mut fut = pool.call(req.clone()); assert!(lazy(|cx| Pin::new(&mut fut).poll(cx)).await.is_pending()); - assert_eq!(pool.waiters.borrow().waiters.len(), 1); + assert_eq!(pool.get_ref().waiters.borrow().waiters.len(), 1); conn.release(false); - assert_eq!(pool.inner.borrow().acquired, 0); - assert_eq!(pool.inner.borrow().available.len(), 1); + assert_eq!(pool.get_ref().inner.borrow().acquired, 0); + assert_eq!(pool.get_ref().inner.borrow().available.len(), 1); let conn = fut.await.unwrap(); assert_eq!(store.borrow().len(), 4); - assert!(pool.waiters.borrow().waiters.is_empty()); - assert!(pool.inner.borrow().connecting.is_empty()); - assert_eq!(pool.inner.borrow().acquired, 1); + assert!(pool.get_ref().waiters.borrow().waiters.is_empty()); + assert!(pool.get_ref().inner.borrow().connecting.is_empty()); + assert_eq!(pool.get_ref().inner.borrow().acquired, 1); conn.release(false); - assert_eq!(pool.inner.borrow().acquired, 0); - assert_eq!(pool.inner.borrow().available.len(), 2); + assert_eq!(pool.get_ref().inner.borrow().acquired, 0); + assert_eq!(pool.get_ref().inner.borrow().available.len(), 2); assert!(lazy(|cx| pool.poll_ready(cx)).await.is_ready()); assert!(lazy(|cx| pool.poll_shutdown(cx)).await.is_ready());