diff --git a/library/alloc/src/bstr.rs b/library/alloc/src/bstr.rs index 338c7ac7f8876..4a9ce05f8b45b 100644 --- a/library/alloc/src/bstr.rs +++ b/library/alloc/src/bstr.rs @@ -204,6 +204,7 @@ impl Default for ByteString { // // #[unstable(feature = "bstr", issue = "134915")] // impl From> for ByteString { +// /// Make a `ByteString` with `Vec` as inner // #[inline] // fn from(s: Vec) -> Self { // ByteString(s) @@ -222,6 +223,7 @@ impl From for Vec { // // #[unstable(feature = "bstr", issue = "134915")] // impl<'a> From<&'a str> for ByteString { +// /// Allocate a new `ByteString` with a copy of the bytes in the slice. // #[inline] // fn from(s: &'a str) -> Self { // ByteString(s.as_bytes().to_vec()) @@ -238,6 +240,7 @@ impl From for Vec { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for ByteString { + /// Allocates a `ByteString` containing the bytes of `ByteStr`. #[inline] fn from(s: &'a ByteStr) -> Self { ByteString(s.0.to_vec()) @@ -246,6 +249,7 @@ impl<'a> From<&'a ByteStr> for ByteString { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From for Cow<'a, ByteStr> { + /// Wrap `ByteString` in `Cow::Owned`. #[inline] fn from(s: ByteString) -> Self { Cow::Owned(s) @@ -254,6 +258,7 @@ impl<'a> From for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteString> for Cow<'a, ByteStr> { + /// Wrap `ByteString` as byte str in `Cow::Borrowed`. #[inline] fn from(s: &'a ByteString) -> Self { Cow::Borrowed(s.as_bytestr()) @@ -599,6 +604,7 @@ impl Clone for Box { #[unstable(feature = "bstr", issue = "134915")] impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { + /// Wrap `ByteStr` in `Cow::Borrowed`. #[inline] fn from(s: &'a ByteStr) -> Self { Cow::Borrowed(s) @@ -607,6 +613,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box { + /// Move the bytes from `Box` to `Box<[u8]>`, this does not allocate new memory. #[inline] fn from(s: Box<[u8]>) -> Box { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -616,6 +623,7 @@ impl From> for Box { #[unstable(feature = "bstr", issue = "134915")] impl From> for Box<[u8]> { + /// Convert the inner bytes of `Box<[u8]>` to `ByteStr`. #[inline] fn from(s: Box) -> Box<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -626,6 +634,7 @@ impl From> for Box<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc { + /// Create an `Rc<[u8]>` from the inner bytes of `Rc`. #[inline] fn from(s: Rc<[u8]>) -> Rc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -636,6 +645,7 @@ impl From> for Rc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(not(no_rc))] impl From> for Rc<[u8]> { + /// Create a `Rc` from the bytes of `Rc<[u8]>`. #[inline] fn from(s: Rc) -> Rc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -646,6 +656,7 @@ impl From> for Rc<[u8]> { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc { + /// Create an `Arc` from the bytes of `Arc<[u8]>`. #[inline] fn from(s: Arc<[u8]>) -> Arc { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -656,6 +667,7 @@ impl From> for Arc { #[unstable(feature = "bstr", issue = "134915")] #[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))] impl From> for Arc<[u8]> { + /// Create a `Arc<[u8]>` from the inner bytes of `Arc`. #[inline] fn from(s: Arc) -> Arc<[u8]> { // SAFETY: `ByteStr` is a transparent wrapper around `[u8]`. @@ -675,6 +687,10 @@ impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>); impl<'a> TryFrom<&'a ByteStr> for String { type Error = core::str::Utf8Error; + /// Try to allocate a `ByteStr`s bytes as a UTF-8 `String`. + /// + /// # Errors + /// If `ByteStr` is not valid UTF-8 #[inline] fn try_from(s: &'a ByteStr) -> Result { Ok(core::str::from_utf8(&s.0)?.into()) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index f8844e2d3a5cb..656d52d179116 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -3045,6 +3045,7 @@ impl From> for VecDeque { /// [`Vec`]: crate::vec::Vec /// [`VecDeque`]: crate::collections::VecDeque /// + /// ## Cost /// This conversion is guaranteed to run in *O*(1) time /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index b4116f4988b64..b9043845d9e5b 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -107,9 +107,7 @@ pub trait Wake { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for Waker { - /// Use a [`Wake`]-able type as a `Waker`. - /// - /// No heap allocations or atomic operations are used for this conversion. + /// Use a [`Wake`]-able type as a `Waker`, without any heap allocations or atomic operations. fn from(waker: Arc) -> Waker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Arc. @@ -119,9 +117,7 @@ impl From> for Waker { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. - /// - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `Wake`-able type as a `RawWaker`, without any heap allocations or atomic operations. fn from(waker: Arc) -> RawWaker { raw_waker(waker) } @@ -286,9 +282,7 @@ pub trait LocalWake { #[unstable(feature = "local_waker", issue = "118959")] impl From> for LocalWaker { - /// Use a `Wake`-able type as a `LocalWaker`. - /// - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `LocalWake`-able type as a `LocalWaker`, without any heap allocations or atomic operations. fn from(waker: Rc) -> LocalWaker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Rc. @@ -298,9 +292,7 @@ impl From> for LocalWaker { #[allow(ineffective_unstable_trait_impl)] #[unstable(feature = "local_waker", issue = "118959")] impl From> for RawWaker { - /// Use a `Wake`-able type as a `RawWaker`. - /// - /// No heap allocations or atomic operations are used for this conversion. + /// Use a `LocalWake`-able type as a `RawWaker`, without any heap allocations or atomic operations. fn from(waker: Rc) -> RawWaker { local_raw_waker(waker) } diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 48de4f17b1b3a..aba6530f6f357 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -546,6 +546,7 @@ macro_rules! into_int_impl { $( #[unstable(feature = "ascii_char", issue = "110998")] impl From for $ty { + #[doc = concat!("Convert `AsciiChar` as `u8` into `", stringify!($ty), "`")] #[inline] fn from(chr: AsciiChar) -> $ty { chr as u8 as $ty diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 7585ec140e31e..25b37a468e28e 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -290,6 +290,7 @@ impl From> for T where T: ZeroablePrimitive, { + /// Returns the contained value as a primitive type. #[inline] fn from(nonzero: NonZero) -> Self { // Call `get` method to keep range information. diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index c769ba673c61e..ced6bdbd4e089 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1648,6 +1648,7 @@ impl hash::Hash for NonNull { #[unstable(feature = "ptr_internals", issue = "none")] impl From> for NonNull { + /// Cast `Unique` to a `NonNull`. #[inline] fn from(unique: Unique) -> Self { unique.as_non_null_ptr() diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index 340b0b79e40a3..14b57ea89dc2c 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -164,6 +164,7 @@ impl Exclusive { #[unstable(feature = "exclusive_wrapper", issue = "98407")] impl From for Exclusive { + /// Creates a new `Exclusive` wrapping `T`. #[inline] fn from(t: T) -> Self { Self::new(t) diff --git a/library/portable-simd/crates/core_simd/src/masks.rs b/library/portable-simd/crates/core_simd/src/masks.rs index 19d45f4d3b31a..bae7d77a4e815 100644 --- a/library/portable-simd/crates/core_simd/src/masks.rs +++ b/library/portable-simd/crates/core_simd/src/masks.rs @@ -378,6 +378,7 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + /// Uses `from_array` to create a new `Mask` #[inline] fn from(array: [bool; N]) -> Self { Self::from_array(array) @@ -389,6 +390,7 @@ where T: MaskElement, LaneCount: SupportedLaneCount, { + /// Converts a SIMD mask to an array of bools. #[inline] fn from(vector: Mask) -> Self { vector.to_array() @@ -634,6 +636,7 @@ macro_rules! impl_from { where LaneCount: SupportedLaneCount, { + /// Casts the value into the other `Mask` #[inline] fn from(value: Mask<$from, N>) -> Self { value.cast() diff --git a/library/portable-simd/crates/core_simd/src/vector.rs b/library/portable-simd/crates/core_simd/src/vector.rs index d76a6cd52bfc5..3d9937f818a66 100644 --- a/library/portable-simd/crates/core_simd/src/vector.rs +++ b/library/portable-simd/crates/core_simd/src/vector.rs @@ -1047,6 +1047,7 @@ where LaneCount: SupportedLaneCount, T: SimdElement, { + /// Load the array into a new `Simd` #[inline] fn from(array: [T; N]) -> Self { Self::from_array(array) diff --git a/library/portable-simd/crates/core_simd/src/vendor.rs b/library/portable-simd/crates/core_simd/src/vendor.rs index 57536e4fc77dc..e37e378540d5f 100644 --- a/library/portable-simd/crates/core_simd/src/vendor.rs +++ b/library/portable-simd/crates/core_simd/src/vendor.rs @@ -7,6 +7,7 @@ macro_rules! from_transmute { }; { @impl $from:ty => $to:ty } => { impl core::convert::From<$from> for $to { + #[doc = concat!("Transmute a `", stringify!($from), "` into a `", stringify!($to), "`")] #[inline] fn from(value: $from) -> $to { // Safety: transmuting between vectors is safe, but the caller of this macro diff --git a/library/proc_macro/src/bridge/buffer.rs b/library/proc_macro/src/bridge/buffer.rs index 3760749d83a54..8949d08a654c9 100644 --- a/library/proc_macro/src/bridge/buffer.rs +++ b/library/proc_macro/src/bridge/buffer.rs @@ -127,6 +127,7 @@ impl Drop for Buffer { } impl From> for Buffer { + /// Create a `Buffer` without allocation. fn from(v: Vec) -> Self { let mut v = ManuallyDrop::new(v); let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity()); diff --git a/library/proc_macro/src/bridge/closure.rs b/library/proc_macro/src/bridge/closure.rs index e0e688434dce5..4d0a251766aac 100644 --- a/library/proc_macro/src/bridge/closure.rs +++ b/library/proc_macro/src/bridge/closure.rs @@ -17,6 +17,7 @@ pub(super) struct Closure<'a, A, R> { struct Env; impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> { + /// Create a `Closure` from an `FnMut` eg.(function, `||` closure) fn from(f: &'a mut F) -> Self { unsafe extern "C" fn call R>(env: *mut Env, arg: A) -> R { unsafe { (*(env as *mut _ as *mut F))(arg) } diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 85fd7d138585c..f4d310257cce0 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -253,6 +253,7 @@ pub enum PanicMessage { } impl From> for PanicMessage { + /// Extract `String` or `&'static str` payloads if available or default to `Unknown` fn from(payload: Box) -> Self { if let Some(s) = payload.downcast_ref::<&'static str>() { return PanicMessage::StaticStr(s); @@ -265,6 +266,7 @@ impl From> for PanicMessage { } impl From for Box { + /// Wrap the inner message in a newly allocated `Box`. fn from(val: PanicMessage) -> Self { match val { PanicMessage::StaticStr(s) => Box::new(s), diff --git a/library/std/src/error.rs b/library/std/src/error.rs index def5f984c88e4..61059f70d5223 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -511,6 +511,7 @@ impl From for Report where E: Error, { + /// Create a `Report` with error of `E`, with all other parameters `false` fn from(error: E) -> Self { Report { error, show_backtrace: false, pretty: false } } diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 475d877528f7f..73d5b2856931b 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -173,6 +173,7 @@ impl IntoInnerError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for Error { + /// Extracts the inner [`Error`]. Equivalent to [`into_error`](IntoInnerError::into_error). fn from(iie: IntoInnerError) -> Error { iie.1 } diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 9195909479729..ea49c9afb60fd 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -137,6 +137,7 @@ impl From for PidFd { } impl From for OwnedFd { + /// Get the inner of `PidFd` fn from(pid_fd: PidFd) -> Self { pid_fd.into_inner().into_inner().into_inner() } diff --git a/library/std/src/os/solid/io.rs b/library/std/src/os/solid/io.rs index c23d842b238b8..e95ae309d490e 100644 --- a/library/std/src/os/solid/io.rs +++ b/library/std/src/os/solid/io.rs @@ -243,6 +243,7 @@ macro_rules! impl_owned_fd_traits { } impl From for OwnedFd { + #[doc = concat!("Create a `OwnedFd` from inner `", stringify!($t), "`")] #[inline] fn from(socket: net::$t) -> OwnedFd { socket.into_inner().into_socket().into_inner() @@ -250,6 +251,7 @@ macro_rules! impl_owned_fd_traits { } impl From for net::$t { + #[doc = concat!("Create a `", stringify!($t), "` with inner `OwnedFd`")] #[inline] fn from(owned_fd: OwnedFd) -> Self { Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd))) diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 7735637c84059..ece253153c40a 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -981,6 +981,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixDatagram { + /// Takes ownership of a [`OwnedFd`]'s socket file descriptor. #[inline] fn from(owned: OwnedFd) -> Self { unsafe { Self::from_raw_fd(owned.into_raw_fd()) } diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 1cab04a454dc0..48c0641485b98 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -694,6 +694,7 @@ impl From for OwnedFd { #[stable(feature = "io_safety", since = "1.63.0")] impl From for UnixStream { + /// Takes ownership of a [`OwnedFd`]'s socket file descriptor. #[inline] fn from(owned: OwnedFd) -> Self { unsafe { Self::from_raw_fd(owned.into_raw_fd()) } diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 7f21929b85f99..b1f4c19f50e4f 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -655,6 +655,7 @@ impl AsHandle for crate::thread::JoinHandle { #[stable(feature = "io_safety", since = "1.63.0")] impl From> for OwnedHandle { + /// Get the inner handle of `JoinHandle`. #[inline] fn from(join_handle: crate::thread::JoinHandle) -> OwnedHandle { join_handle.into_inner().into_handle().into_inner() diff --git a/library/std/src/os/xous/ffi/definitions.rs b/library/std/src/os/xous/ffi/definitions.rs index 345005bcc78d7..9c68485628f66 100644 --- a/library/std/src/os/xous/ffi/definitions.rs +++ b/library/std/src/os/xous/ffi/definitions.rs @@ -79,6 +79,7 @@ pub enum Error { #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { + /// Convert an error code to an `Error` fn from(src: usize) -> Self { match src { 0 => Self::NoError, @@ -115,6 +116,7 @@ impl From for Error { #[stable(feature = "rust1", since = "1.0.0")] impl From for Error { + /// Convert `i32` to an `Error`, if the conversion fails it `UnknownError` is returned fn from(src: i32) -> Self { let Ok(src) = core::convert::TryInto::::try_into(src) else { return Self::UnknownError; @@ -193,6 +195,7 @@ pub struct Connection(u32); #[stable(feature = "rust1", since = "1.0.0")] impl From for Connection { + /// Make a `Connection` with `u32` as inner fn from(src: u32) -> Connection { Connection(src) } @@ -263,6 +266,7 @@ impl Into<[u32; 4]> for ServerAddress { pub(crate) struct ThreadId(usize); impl From for ThreadId { + /// Make a `ThreadId` with `usize` as the id fn from(src: usize) -> ThreadId { ThreadId(src) } diff --git a/library/std/src/process.rs b/library/std/src/process.rs index f81ce8e1a1a1e..8ca8f0de1bb09 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -1923,6 +1923,7 @@ impl ExitStatusError { #[unstable(feature = "exit_status_error", issue = "84908")] impl From for ExitStatus { + /// Converts an `ExitStatusError` (back) to an `ExitStatus`. fn from(error: ExitStatusError) -> Self { Self(error.0.into()) } diff --git a/library/std/src/sync/mpmc/error.rs b/library/std/src/sync/mpmc/error.rs index e34b56d08312b..8027dd2e9dca6 100644 --- a/library/std/src/sync/mpmc/error.rs +++ b/library/std/src/sync/mpmc/error.rs @@ -41,6 +41,7 @@ impl error::Error for SendTimeoutError {} #[unstable(feature = "mpmc_channel", issue = "126840")] impl From> for SendTimeoutError { + /// Wrap a `SendError` in the `Disconnected` variant. fn from(err: SendError) -> SendTimeoutError { match err { SendError(e) => SendTimeoutError::Disconnected(e), diff --git a/library/std/src/sync/mpmc/select.rs b/library/std/src/sync/mpmc/select.rs index 56a83fee2e119..34340b5b693a2 100644 --- a/library/std/src/sync/mpmc/select.rs +++ b/library/std/src/sync/mpmc/select.rs @@ -47,6 +47,7 @@ pub enum Selected { } impl From for Selected { + /// Make a `Selected` from a `usize`, 0-2 match specific variants, the rest matches `Operation` #[inline] fn from(val: usize) -> Selected { match val { diff --git a/library/std/src/sync/mpsc.rs b/library/std/src/sync/mpsc.rs index f942937c14d11..f99eeb2c6333e 100644 --- a/library/std/src/sync/mpsc.rs +++ b/library/std/src/sync/mpsc.rs @@ -1148,6 +1148,7 @@ impl From> for TrySendError { /// /// This conversion always returns a `TrySendError::Disconnected` containing the data in the `SendError`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: SendError) -> TrySendError { match err { @@ -1198,6 +1199,7 @@ impl From for TryRecvError { /// /// This conversion always returns `TryRecvError::Disconnected`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: RecvError) -> TryRecvError { match err { @@ -1233,6 +1235,7 @@ impl From for RecvTimeoutError { /// /// This conversion always returns `RecvTimeoutError::Disconnected`. /// + /// ## Cost /// No data is allocated on the heap. fn from(err: RecvError) -> RecvTimeoutError { match err { diff --git a/library/std/src/sync/poison.rs b/library/std/src/sync/poison.rs index 1b8809734b8a8..b25ef7840bdb0 100644 --- a/library/std/src/sync/poison.rs +++ b/library/std/src/sync/poison.rs @@ -340,6 +340,7 @@ impl PoisonError { #[stable(feature = "rust1", since = "1.0.0")] impl From> for TryLockError { + /// Wrap a `PoisonError` in the `Poisoned` variant. fn from(err: PoisonError) -> TryLockError { TryLockError::Poisoned(err) } diff --git a/library/std/src/sync/reentrant_lock.rs b/library/std/src/sync/reentrant_lock.rs index e009eb410efc0..3ed11e6dc365d 100644 --- a/library/std/src/sync/reentrant_lock.rs +++ b/library/std/src/sync/reentrant_lock.rs @@ -373,6 +373,7 @@ impl Default for ReentrantLock { #[unstable(feature = "reentrant_lock", issue = "121440")] impl From for ReentrantLock { + /// Create a new `ReentrantLock` wrapping `T` fn from(t: T) -> Self { Self::new(t) } diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 06bba019393a5..d57b4cfa55767 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1057,6 +1057,7 @@ impl FileAttr { } } impl From for FileAttr { + /// Map `c::WIN32_FIND_DATAW`s fields to a `FileAttr`. fn from(wfd: c::WIN32_FIND_DATAW) -> Self { FileAttr { attributes: wfd.dwFileAttributes, diff --git a/library/std/src/sys/pal/windows/time.rs b/library/std/src/sys/pal/windows/time.rs index d9010e3996109..66ccd8762512a 100644 --- a/library/std/src/sys/pal/windows/time.rs +++ b/library/std/src/sys/pal/windows/time.rs @@ -133,6 +133,7 @@ impl fmt::Debug for SystemTime { } impl From for SystemTime { + /// Wrap `c::FILETIME` in `SystemTime`. fn from(t: c::FILETIME) -> SystemTime { SystemTime { t } } @@ -187,6 +188,10 @@ mod perf_counter { } } impl From for super::Instant { + /// Use `PerformanceCounterInstant` to get instant in nano sec, then make a `Duration` from nanos. + /// + /// ## Cost + /// This calls a function that makes an atomic oparation fn from(other: PerformanceCounterInstant) -> Self { let freq = frequency() as u64; let instant_nsec = mul_div_u64(other.ts as u64, NANOS_PER_SEC, freq); diff --git a/library/std/src/sys/process/uefi.rs b/library/std/src/sys/process/uefi.rs index b46418ae9bb67..8b3185b26e37d 100644 --- a/library/std/src/sys/process/uefi.rs +++ b/library/std/src/sys/process/uefi.rs @@ -181,6 +181,7 @@ impl Command { } impl From for Stdio { + /// Diverge the `Pipe`. fn from(pipe: AnonPipe) -> Stdio { pipe.diverge() } @@ -272,6 +273,7 @@ impl ExitCode { } impl From for ExitCode { + /// Match `u8` to a `ExitCode` variant, 0 is `SUCCESS`, else is `FAILURE`. fn from(code: u8) -> Self { match code { 0 => Self::SUCCESS, diff --git a/library/std/src/sys/process/unix/common.rs b/library/std/src/sys/process/unix/common.rs index 8bc17f314911d..a52da5f392bf5 100644 --- a/library/std/src/sys/process/unix/common.rs +++ b/library/std/src/sys/process/unix/common.rs @@ -639,6 +639,7 @@ impl ExitCode { } impl From for ExitCode { + /// Take code by wrapping it in `ExitCode`. fn from(code: u8) -> Self { Self(code) } diff --git a/library/std/src/sys/process/unix/fuchsia.rs b/library/std/src/sys/process/unix/fuchsia.rs index 0de32ecffd4b0..8616ebb467b77 100644 --- a/library/std/src/sys/process/unix/fuchsia.rs +++ b/library/std/src/sys/process/unix/fuchsia.rs @@ -290,6 +290,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a as i64) } diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 42542f81b6545..7abf54ee96ecd 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -1085,6 +1085,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a) } diff --git a/library/std/src/sys/process/unix/unsupported/wait_status.rs b/library/std/src/sys/process/unix/unsupported/wait_status.rs index f348d557e4b7e..10d61748ccb54 100644 --- a/library/std/src/sys/process/unix/unsupported/wait_status.rs +++ b/library/std/src/sys/process/unix/unsupported/wait_status.rs @@ -21,6 +21,7 @@ pub struct ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(wait_status: c_int) -> ExitStatus { ExitStatus { wait_status } } diff --git a/library/std/src/sys/process/unix/vxworks.rs b/library/std/src/sys/process/unix/vxworks.rs index 5f1727789a1bc..b9c1e90f66a2f 100644 --- a/library/std/src/sys/process/unix/vxworks.rs +++ b/library/std/src/sys/process/unix/vxworks.rs @@ -236,6 +236,7 @@ impl ExitStatus { /// Converts a raw `c_int` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `c_int` in a type-safe `ExitStatus` fn from(a: c_int) -> ExitStatus { ExitStatus(a) } diff --git a/library/std/src/sys/process/unsupported.rs b/library/std/src/sys/process/unsupported.rs index fee81744f09ec..158b7a23b754e 100644 --- a/library/std/src/sys/process/unsupported.rs +++ b/library/std/src/sys/process/unsupported.rs @@ -111,24 +111,28 @@ impl Command { } impl From for Stdio { + /// Diverge pipe into `Stdio` fn from(pipe: AnonPipe) -> Stdio { pipe.diverge() } } impl From for Stdio { + /// Return a `Stdio::ParentStdout`. fn from(_: io::Stdout) -> Stdio { Stdio::ParentStdout } } impl From for Stdio { + /// Return a `Stdio::ParentStderr`. fn from(_: io::Stderr) -> Stdio { Stdio::ParentStderr } } impl From for Stdio { + /// Wrap `File` in a `Stdio::InheritFile`. fn from(file: File) -> Stdio { Stdio::InheritFile(file) } @@ -267,6 +271,7 @@ impl ExitCode { } impl From for ExitCode { + /// Take `u8` by wrapping it in `ExitCode`. fn from(code: u8) -> Self { Self(code) } diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index 06c15e08f3fb1..b4f7530bf1720 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -109,6 +109,7 @@ impl PartialOrd for EnvKey { } impl PartialEq for EnvKey { fn eq(&self, other: &str) -> bool { + // Save an allocation if lengths are different if self.os_string.len() != other.len() { false } else { @@ -120,18 +121,27 @@ impl PartialEq for EnvKey { // Environment variable keys should preserve their original case even though // they are compared using a caseless string mapping. impl From for EnvKey { + /// Create a new `EnvKey` from `OsString`. + /// + /// ## Cost + /// Has to collect `OsString.encode_wide` which allocates a new `Vec` fn from(k: OsString) -> Self { EnvKey { utf16: k.encode_wide().collect(), os_string: k } } } impl From for OsString { + /// Return the inner `OsString` of the `EnvKey` fn from(k: EnvKey) -> Self { k.os_string } } impl From<&OsStr> for EnvKey { + /// Uses `EnvKey::From` to convert the `&OsStr`. + /// + /// ## Cost + /// Converts `&OsStr` to `OsString` which does a heap allocation fn from(k: &OsStr) -> Self { Self::from(k.to_os_string()) } @@ -609,6 +619,7 @@ impl Stdio { } impl From for Stdio { + /// Wrap `AnonPipe` in the `Pipe` variant fn from(pipe: AnonPipe) -> Stdio { Stdio::Pipe(pipe) } @@ -621,12 +632,14 @@ impl From for Stdio { } impl From for Stdio { + /// Wrap `File`s inner in the `Handle` variant fn from(file: File) -> Stdio { Stdio::Handle(file.into_inner()) } } impl From for Stdio { + /// Create a new `Stdio::InheritSpecific` with `c::STD_OUTPUT_HANDLE` fn from(_: io::Stdout) -> Stdio { Stdio::InheritSpecific { from_stdio_id: c::STD_OUTPUT_HANDLE } } @@ -728,6 +741,7 @@ impl ExitStatus { /// Converts a raw `u32` to a type-safe `ExitStatus` by wrapping it without copying. impl From for ExitStatus { + /// Wrap `u32` in a type-safe `ExitStatus` fn from(u: u32) -> ExitStatus { ExitStatus(u) } @@ -777,12 +791,14 @@ impl ExitCode { } impl From for ExitCode { + /// Convert the `u8` then wrap it in a `ExitCode` fn from(code: u8) -> Self { ExitCode(u32::from(code)) } } impl From for ExitCode { + /// Wrap the `u32` in a `ExitCode` fn from(code: u32) -> Self { ExitCode(u32::from(code)) } diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 3f3ba02361cc8..5ab936e089e2a 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1265,6 +1265,7 @@ mod thread_name_string { } impl From for ThreadNameString { + /// Convert `String` to a `CString` then use that as the `ThreadNameString` inner fn from(s: String) -> Self { Self { inner: CString::new(s).expect("thread name may not contain interior null bytes"),