Skip to content

Commit a47f69f

Browse files
committed
Add from docs to all impls in lib std and core
1 parent d07d7fc commit a47f69f

File tree

49 files changed

+165
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+165
-0
lines changed

library/alloc/src/bstr.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ impl Default for ByteString {
184184
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
185185
// #[unstable(feature = "bstr", issue = "134915")]
186186
// impl<'a, const N: usize> From<&'a [u8; N]> for ByteString {
187+
// /// Make a `ByteString` from a byte array ref.
188+
// ///
189+
// /// ## Cost
190+
// /// Allocates a new `Vec`
187191
// #[inline]
188192
// fn from(s: &'a [u8; N]) -> Self {
189193
// ByteString(s.as_slice().to_vec())
@@ -193,6 +197,10 @@ impl Default for ByteString {
193197
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
194198
// #[unstable(feature = "bstr", issue = "134915")]
195199
// impl<const N: usize> From<[u8; N]> for ByteString {
200+
// /// Make a `ByteString` from a byte array.
201+
// ///
202+
// /// ## Cost
203+
// /// Allocates a new `Vec`
196204
// #[inline]
197205
// fn from(s: [u8; N]) -> Self {
198206
// ByteString(s.as_slice().to_vec())
@@ -202,6 +210,10 @@ impl Default for ByteString {
202210
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
203211
// #[unstable(feature = "bstr", issue = "134915")]
204212
// impl<'a> From<&'a [u8]> for ByteString {
213+
// /// Make a `ByteString` from a byte slice.
214+
// ///
215+
// /// ## Cost
216+
// /// Allocates a new `Vec`
205217
// #[inline]
206218
// fn from(s: &'a [u8]) -> Self {
207219
// ByteString(s.to_vec())
@@ -210,6 +222,7 @@ impl Default for ByteString {
210222
//
211223
// #[unstable(feature = "bstr", issue = "134915")]
212224
// impl From<Vec<u8>> for ByteString {
225+
// /// Make a `ByteString` with `Vec<u8>` as inner
213226
// #[inline]
214227
// fn from(s: Vec<u8>) -> Self {
215228
// ByteString(s)
@@ -218,6 +231,7 @@ impl Default for ByteString {
218231

219232
#[unstable(feature = "bstr", issue = "134915")]
220233
impl From<ByteString> for Vec<u8> {
234+
/// Return the inner `Vec` of the byte string
221235
#[inline]
222236
fn from(s: ByteString) -> Self {
223237
s.0
@@ -229,6 +243,10 @@ impl From<ByteString> for Vec<u8> {
229243
// #[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
230244
// #[unstable(feature = "bstr", issue = "134915")]
231245
// impl<'a> From<&'a str> for ByteString {
246+
// /// Make a `ByteString` from a string slices bytes.
247+
// ///
248+
// /// ## Cost
249+
// /// Allocates a new `Vec`
232250
// #[inline]
233251
// fn from(s: &'a str) -> Self {
234252
// ByteString(s.as_bytes().to_vec())
@@ -237,6 +255,7 @@ impl From<ByteString> for Vec<u8> {
237255
//
238256
// #[unstable(feature = "bstr", issue = "134915")]
239257
// impl From<String> for ByteString {
258+
// /// Create a `ByteString` from a `String`s bytes
240259
// #[inline]
241260
// fn from(s: String) -> Self {
242261
// ByteString(s.into_bytes())
@@ -617,6 +636,7 @@ impl Clone for Box<ByteStr> {
617636
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
618637
#[unstable(feature = "bstr", issue = "134915")]
619638
impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
639+
/// Create a `Borrowed` cow from a `ByteStr`
620640
#[inline]
621641
fn from(s: &'a ByteStr) -> Self {
622642
Cow::Borrowed(s)
@@ -626,6 +646,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {
626646
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
627647
#[unstable(feature = "bstr", issue = "134915")]
628648
impl From<Box<[u8]>> for Box<ByteStr> {
649+
/// Create a `Box<[u8]>` from `Box<ByteStr>`s raw
629650
#[inline]
630651
fn from(s: Box<[u8]>) -> Box<ByteStr> {
631652
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -636,6 +657,7 @@ impl From<Box<[u8]>> for Box<ByteStr> {
636657
#[cfg(not(test))] // https://github.com/rust-lang/rust/issues/135100
637658
#[unstable(feature = "bstr", issue = "134915")]
638659
impl From<Box<ByteStr>> for Box<[u8]> {
660+
/// Create a `Box<ByteStr>` from `Box<[u8]>`s raw
639661
#[inline]
640662
fn from(s: Box<ByteStr>) -> Box<[u8]> {
641663
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -646,6 +668,7 @@ impl From<Box<ByteStr>> for Box<[u8]> {
646668
#[unstable(feature = "bstr", issue = "134915")]
647669
#[cfg(not(no_rc))]
648670
impl From<Rc<[u8]>> for Rc<ByteStr> {
671+
/// Create a `Rc<[u8]>` from `Rc<ByteStr>`s raw
649672
#[inline]
650673
fn from(s: Rc<[u8]>) -> Rc<ByteStr> {
651674
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -656,6 +679,7 @@ impl From<Rc<[u8]>> for Rc<ByteStr> {
656679
#[unstable(feature = "bstr", issue = "134915")]
657680
#[cfg(not(no_rc))]
658681
impl From<Rc<ByteStr>> for Rc<[u8]> {
682+
/// Create a `Rc<ByteStr>` from `Rc<[u8]>`s raw
659683
#[inline]
660684
fn from(s: Rc<ByteStr>) -> Rc<[u8]> {
661685
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -666,6 +690,7 @@ impl From<Rc<ByteStr>> for Rc<[u8]> {
666690
#[unstable(feature = "bstr", issue = "134915")]
667691
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
668692
impl From<Arc<[u8]>> for Arc<ByteStr> {
693+
/// Create a `Arc<ByteStr>` from `Arc<[u8]>`s raw
669694
#[inline]
670695
fn from(s: Arc<[u8]>) -> Arc<ByteStr> {
671696
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -676,6 +701,7 @@ impl From<Arc<[u8]>> for Arc<ByteStr> {
676701
#[unstable(feature = "bstr", issue = "134915")]
677702
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
678703
impl From<Arc<ByteStr>> for Arc<[u8]> {
704+
/// Create a `Arc<ByteStr>` from `Arc<[u8]>`s raw
679705
#[inline]
680706
fn from(s: Arc<ByteStr>) -> Arc<[u8]> {
681707
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
@@ -695,6 +721,10 @@ impl_partial_eq_ord_cow!(&'a ByteStr, Cow<'a, [u8]>);
695721
impl<'a> TryFrom<&'a ByteStr> for String {
696722
type Error = core::str::Utf8Error;
697723

724+
/// Convert `ByteStr`s bytes to a utf-8 `String`.
725+
///
726+
/// # Errors
727+
/// If `ByteStr` is not valid utf-8
698728
#[inline]
699729
fn try_from(s: &'a ByteStr) -> Result<Self, Self::Error> {
700730
Ok(core::str::from_utf8(&s.0)?.into())

library/alloc/src/collections/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub enum TryReserveErrorKind {
109109
issue = "48043"
110110
)]
111111
impl From<TryReserveErrorKind> for TryReserveError {
112+
/// Wrap kind in `TryReserveError`.
112113
#[inline]
113114
fn from(kind: TryReserveErrorKind) -> Self {
114115
Self { kind }

library/alloc/src/task.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub trait Wake {
109109
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
110110
/// Use a [`Wake`]-able type as a `Waker`.
111111
///
112+
/// ## Cost
112113
/// No heap allocations or atomic operations are used for this conversion.
113114
fn from(waker: Arc<W>) -> Waker {
114115
// SAFETY: This is safe because raw_waker safely constructs
@@ -121,6 +122,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
121122
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
122123
/// Use a `Wake`-able type as a `RawWaker`.
123124
///
125+
/// ## Cost
124126
/// No heap allocations or atomic operations are used for this conversion.
125127
fn from(waker: Arc<W>) -> RawWaker {
126128
raw_waker(waker)
@@ -288,6 +290,7 @@ pub trait LocalWake {
288290
impl<W: LocalWake + 'static> From<Rc<W>> for LocalWaker {
289291
/// Use a `Wake`-able type as a `LocalWaker`.
290292
///
293+
/// ## Cost
291294
/// No heap allocations or atomic operations are used for this conversion.
292295
fn from(waker: Rc<W>) -> LocalWaker {
293296
// SAFETY: This is safe because raw_waker safely constructs
@@ -300,6 +303,7 @@ impl<W: LocalWake + 'static> From<Rc<W>> for LocalWaker {
300303
impl<W: LocalWake + 'static> From<Rc<W>> for RawWaker {
301304
/// Use a `Wake`-able type as a `RawWaker`.
302305
///
306+
/// ## Cost
303307
/// No heap allocations or atomic operations are used for this conversion.
304308
fn from(waker: Rc<W>) -> RawWaker {
305309
local_raw_waker(waker)

library/core/src/array/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,24 @@ impl Error for TryFromSliceError {
178178

179179
#[stable(feature = "try_from_slice_error", since = "1.36.0")]
180180
impl From<Infallible> for TryFromSliceError {
181+
/// Match `Infallible` into `TryFromSliceError`.
181182
fn from(x: Infallible) -> TryFromSliceError {
182183
match x {}
183184
}
184185
}
185186

187+
#[unstable(feature = "never_type", issue = "35121")]
188+
impl From<!> for TryFromSliceError {
189+
/// Match `!` into `TryFromSliceError`.
190+
#[inline]
191+
fn from(never: !) -> TryFromSliceError {
192+
// Match rather than coerce to make sure that code like
193+
// `From<Infallible> for TryFromSliceError` above will keep working
194+
// when `Infallible` becomes an alias to `!`.
195+
match never {}
196+
}
197+
}
198+
186199
#[stable(feature = "rust1", since = "1.0.0")]
187200
impl<T, const N: usize> AsRef<[T]> for [T; N] {
188201
#[inline]

library/core/src/ascii/ascii_char.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ macro_rules! into_int_impl {
546546
$(
547547
#[unstable(feature = "ascii_char", issue = "110998")]
548548
impl From<AsciiChar> for $ty {
549+
#[doc = concat!("Convert `AsciiChar` as `u8` into `", stringify!($ty), "`")]
549550
#[inline]
550551
fn from(chr: AsciiChar) -> $ty {
551552
chr as u8 as $ty

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub enum Alignment {
3636
#[doc(hidden)]
3737
#[unstable(feature = "fmt_internals", reason = "internal to standard library", issue = "none")]
3838
impl From<rt::Alignment> for Option<Alignment> {
39+
/// Match the `Alignment` to the `Some` equivalent, `Unknown` matches `None`.
3940
fn from(value: rt::Alignment) -> Self {
4041
match value {
4142
rt::Alignment::Left => Some(Alignment::Left),

library/core/src/num/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ impl Error for TryFromIntError {
2727

2828
#[stable(feature = "try_from", since = "1.34.0")]
2929
impl From<Infallible> for TryFromIntError {
30+
/// Match `Infallible` into `TryFromIntError`.
31+
#[inline]
3032
fn from(x: Infallible) -> TryFromIntError {
3133
match x {}
3234
}
3335
}
3436

3537
#[unstable(feature = "never_type", issue = "35121")]
3638
impl From<!> for TryFromIntError {
39+
/// Match `!` into `TryFromIntError`.
3740
#[inline]
3841
fn from(never: !) -> TryFromIntError {
3942
// Match rather than coerce to make sure that code like

library/core/src/num/nonzero.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl<T> From<NonZero<T>> for T
287287
where
288288
T: ZeroablePrimitive,
289289
{
290+
/// Get the inner num of `NonZero`.
290291
#[inline]
291292
fn from(nonzero: NonZero<T>) -> Self {
292293
// Call `get` method to keep range information.

library/core/src/ptr/alignment.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl TryFrom<usize> for Alignment {
189189

190190
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
191191
impl From<Alignment> for NonZero<usize> {
192+
/// `Alignment` is non zero so the inner enum value is returned
192193
#[inline]
193194
fn from(align: Alignment) -> NonZero<usize> {
194195
align.as_nonzero()
@@ -197,6 +198,7 @@ impl From<Alignment> for NonZero<usize> {
197198

198199
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
199200
impl From<Alignment> for usize {
201+
/// `Alignment` is unsined so the inner enum value is returned
200202
#[inline]
201203
fn from(align: Alignment) -> usize {
202204
align.as_usize()

library/core/src/range.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ impl<T> IntoBounds<T> for Range<T> {
187187

188188
#[unstable(feature = "new_range_api", issue = "125687")]
189189
impl<T> From<Range<T>> for legacy::Range<T> {
190+
/// Make a new `legacy::Range` with the same start and end as `Range`
190191
#[inline]
191192
fn from(value: Range<T>) -> Self {
192193
Self { start: value.start, end: value.end }
193194
}
194195
}
195196
#[unstable(feature = "new_range_api", issue = "125687")]
196197
impl<T> From<legacy::Range<T>> for Range<T> {
198+
/// Make a new `Range` with the same start and end as `legacy::Range`
197199
#[inline]
198200
fn from(value: legacy::Range<T>) -> Self {
199201
Self { start: value.start, end: value.end }
@@ -363,13 +365,15 @@ impl<T> IntoBounds<T> for RangeInclusive<T> {
363365

364366
#[unstable(feature = "new_range_api", issue = "125687")]
365367
impl<T> From<RangeInclusive<T>> for legacy::RangeInclusive<T> {
368+
/// Make a new `legacy::RangeInclusive` with the same start and end as `RangeInclusive`
366369
#[inline]
367370
fn from(value: RangeInclusive<T>) -> Self {
368371
Self::new(value.start, value.end)
369372
}
370373
}
371374
#[unstable(feature = "new_range_api", issue = "125687")]
372375
impl<T> From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
376+
/// Make a new `RangeInclusive` with the same start and end as `legacy::RangeInclusive`
373377
#[inline]
374378
fn from(value: legacy::RangeInclusive<T>) -> Self {
375379
assert!(
@@ -507,13 +511,15 @@ impl<T> IntoBounds<T> for RangeFrom<T> {
507511

508512
#[unstable(feature = "new_range_api", issue = "125687")]
509513
impl<T> From<RangeFrom<T>> for legacy::RangeFrom<T> {
514+
/// Make a new `legacy::RangeFrom` with the same start as `RangeFrom`
510515
#[inline]
511516
fn from(value: RangeFrom<T>) -> Self {
512517
Self { start: value.start }
513518
}
514519
}
515520
#[unstable(feature = "new_range_api", issue = "125687")]
516521
impl<T> From<legacy::RangeFrom<T>> for RangeFrom<T> {
522+
/// Make a new `RangeFrom` with the same start as `legacy::RangeFrom`
517523
#[inline]
518524
fn from(value: legacy::RangeFrom<T>) -> Self {
519525
Self { start: value.start }

library/core/src/sync/exclusive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ impl<T: ?Sized> Exclusive<T> {
164164

165165
#[unstable(feature = "exclusive_wrapper", issue = "98407")]
166166
impl<T> From<T> for Exclusive<T> {
167+
/// Creates a new `Exclusive` containing [`T`], wrapping the value in an `Exclusive`
167168
#[inline]
168169
fn from(t: T) -> Self {
169170
Self::new(t)

library/portable-simd/crates/core_simd/src/masks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ where
378378
T: MaskElement,
379379
LaneCount<N>: SupportedLaneCount,
380380
{
381+
/// Uses `from_array` to create a new `Mask`
381382
#[inline]
382383
fn from(array: [bool; N]) -> Self {
383384
Self::from_array(array)
@@ -389,6 +390,10 @@ where
389390
T: MaskElement,
390391
LaneCount<N>: SupportedLaneCount,
391392
{
393+
/// Converts a SIMD mask to an array of bools.
394+
///
395+
/// ## Cost
396+
/// Copies the bytes of the array
392397
#[inline]
393398
fn from(vector: Mask<T, N>) -> Self {
394399
vector.to_array()
@@ -634,6 +639,7 @@ macro_rules! impl_from {
634639
where
635640
LaneCount<N>: SupportedLaneCount,
636641
{
642+
/// Casts the value into the other `Mask`
637643
#[inline]
638644
fn from(value: Mask<$from, N>) -> Self {
639645
value.cast()

library/portable-simd/crates/core_simd/src/masks/full_masks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ where
238238
T: MaskElement,
239239
LaneCount<N>: SupportedLaneCount,
240240
{
241+
/// Return the inner of the `Mask`
241242
#[inline]
242243
fn from(value: Mask<T, N>) -> Self {
243244
value.0

library/portable-simd/crates/core_simd/src/vector.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ where
10471047
LaneCount<N>: SupportedLaneCount,
10481048
T: SimdElement,
10491049
{
1050+
/// Use `from_array` to load the array into a new `Simd`
10501051
#[inline]
10511052
fn from(array: [T; N]) -> Self {
10521053
Self::from_array(array)
@@ -1058,6 +1059,7 @@ where
10581059
LaneCount<N>: SupportedLaneCount,
10591060
T: SimdElement,
10601061
{
1062+
/// Use `to_array` to store the `Simd` into a new array
10611063
#[inline]
10621064
fn from(vector: Simd<T, N>) -> Self {
10631065
vector.to_array()

library/portable-simd/crates/core_simd/src/vendor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ macro_rules! from_transmute {
77
};
88
{ @impl $from:ty => $to:ty } => {
99
impl core::convert::From<$from> for $to {
10+
#[doc = concat!("Transmute a `", stringify!($from), "` into a `", stringify!($to), "`")]
1011
#[inline]
1112
fn from(value: $from) -> $to {
1213
// Safety: transmuting between vectors is safe, but the caller of this macro

library/proc_macro/src/bridge/buffer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl Drop for Buffer {
127127
}
128128

129129
impl From<Vec<u8>> for Buffer {
130+
/// Move data, len, and capacity from `Vec`, then create custom reserve and drop fns.
130131
fn from(v: Vec<u8>) -> Self {
131132
let mut v = ManuallyDrop::new(v);
132133
let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity());

library/proc_macro/src/bridge/closure.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub(super) struct Closure<'a, A, R> {
1717
struct Env;
1818

1919
impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
20+
/// Create a `Closure` from a function
2021
fn from(f: &'a mut F) -> Self {
2122
unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: *mut Env, arg: A) -> R {
2223
unsafe { (*(env as *mut _ as *mut F))(arg) }

0 commit comments

Comments
 (0)