interprocess/
try_clone.rs

1/// Fallible OS object cloning.
2///
3/// The `DuplicateHandle`/`dup` system calls can fail for a variety of reasons, most of them being
4/// related to system resource exhaustion. This trait is implemented by types in Interprocess which
5/// wrap OS objects (which is to say, the majority of types here) to enable handle/file descriptor
6/// duplication functionality on them.
7pub trait TryClone: Sized {
8    /// Clones `self`, possibly returning an error.
9    fn try_clone(&self) -> std::io::Result<Self>;
10}
11impl<T: Clone> TryClone for T {
12    fn try_clone(&self) -> std::io::Result<Self> { Ok(self.clone()) }
13}