瀏覽代碼

Make `AnySocket` object safe

Signed-off-by: Klim Tsoutsman <klim@tsoutsman.com>
Klim Tsoutsman 2 年之前
父節點
當前提交
24af392a25
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      src/socket/mod.rs

+ 10 - 4
src/socket/mod.rs

@@ -91,10 +91,16 @@ impl<'a> Socket<'a> {
 }
 
 /// A conversion trait for network sockets.
-pub trait AnySocket<'a>: Sized {
-    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>;
+pub trait AnySocket<'a> {
+    fn upcast(self) -> Socket<'a>
+    where
+        Self: Sized;
+    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 {