memfile: Added `RawFile::try_link_from()`: Analogue to `try_link_to()`. Instrumented and added panicking versions of both functions. Added `clone_from()` impl that uses `try_link_from()` (i.e. `dup2()`)
if_trace!(error!("`self` and `source` are the same variable. This should never happen!"));
#[cfg(not(feature="logging"))]
panic!("Mutable reference and shared reference point to the same location in memory")
}
}
}
implRawFile
@ -119,8 +142,9 @@ impl RawFile
/// This is a safe wrapper around `dup2()`, as `clone()` is a safe wrapper around `dup()`.
///
/// # Note
/// If `T` is a buffered container (e.g. `std::fs::File`), make sure the buffer is flushed *before* calling this method on it, or the buffered data will be lost.
/// If `T` is a buffered container (e.g. `std::io::BufWriter<T: AsRawFd>`), make sure the buffer is flushed *before* calling this method on it, or the buffered data will be lost.
/// Attempt to link `other`'s contained file descriptor to this instance's fd.
///
/// This is a safe wrapper around `dup2()`, and an analogue of `try_link_to()`.
///
/// # Note
/// After this call succeeds, writing to `self` will have the same effect of writing directly to `other`'s contained file descriptor. If `other` is a buffered stream, you must ensure that `other` has been flushed *before* writing anything to `self`.