Ver Fonte

Make `AnySocket` object safe

Apologies, in #718, removing the sized bound in `downcast` and
`downcast_mut` implicitly made `AnySocket` object unsafe as they don't
have a `self` method. I had a bit of a brain fart.

Signed-off-by: Klim Tsoutsman <klim@tsoutsman.com>
Klim Tsoutsman há 2 anos atrás
pai
commit
33496076a1
1 ficheiros alterados com 6 adições e 2 exclusões
  1. 6 2
      src/socket/mod.rs

+ 6 - 2
src/socket/mod.rs

@@ -93,8 +93,12 @@ impl<'a> Socket<'a> {
 /// A conversion trait for network sockets.
 pub trait AnySocket<'a> {
     fn upcast(self) -> Socket<'a>;
-    fn downcast<'c>(socket: &'c Socket<'a>) -> Option<&'c Self>;
-    fn downcast_mut<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Self>;
+    fn downcast<'c>(socket: &'c Socket<'a>) -> Option<&'c Self>
+    where
+        Self: Sized;
+    fn downcast_mut<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Self>
+    where
+        Self: Sized;
 }
 
 macro_rules! from_socket {