浏览代码

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 2 年之前
父节点
当前提交
33496076a1
共有 1 个文件被更改,包括 6 次插入2 次删除
  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 {