tendermint_std_ext/try_clone.rs
1//! Rust standard library types that can be fallibly cloned.
2
3use std::net::TcpStream;
4
5/// Types that can be cloned where success is not guaranteed can implement this
6/// trait.
7pub trait TryClone: Sized {
8 /// The type of error that can be returned when an attempted clone
9 /// operation fails.
10 type Error: std::error::Error;
11
12 /// Attempt to clone this instance.
13 ///
14 /// # Errors
15 /// Can fail if the underlying instance cannot be cloned (e.g. the OS could
16 /// be out of file descriptors, or some low-level OS-specific error could
17 /// be produced).
18 fn try_clone(&self) -> Result<Self, Self::Error>;
19}
20
21impl TryClone for TcpStream {
22 type Error = std::io::Error;
23
24 fn try_clone(&self) -> Result<Self, Self::Error> {
25 TcpStream::try_clone(self)
26 }
27}