Skip to content

Document From::from impls #137330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions library/alloc/src/bstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl Default for ByteString {
//
// #[unstable(feature = "bstr", issue = "134915")]
// impl From<Vec<u8>> for ByteString {
// /// Make a `ByteString` with `Vec<u8>` as inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// /// Make a `ByteString` with `Vec<u8>` as inner

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clarifies that it is no copy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All From conversions between owned buffers like String, Vec, ByteString, OsString, etc are no copy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a place were that is clearly stated?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// /// Make a `ByteString` with `Vec<u8>` as inner
// /// Wrap `Vec<u8>` with a `ByteString`

// #[inline]
// fn from(s: Vec<u8>) -> Self {
// ByteString(s)
Expand All @@ -222,6 +223,7 @@ impl From<ByteString> for Vec<u8> {
//
// #[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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// /// 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())
Expand All @@ -238,6 +240,7 @@ impl From<ByteString> for Vec<u8> {

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> From<&'a ByteStr> for ByteString {
/// Allocates a `ByteString` containing the bytes of `ByteStr`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Allocates a `ByteString` containing the bytes of `ByteStr`.

#[inline]
fn from(s: &'a ByteStr) -> Self {
ByteString(s.0.to_vec())
Expand All @@ -246,6 +249,7 @@ impl<'a> From<&'a ByteStr> for ByteString {

#[unstable(feature = "bstr", issue = "134915")]
impl<'a> From<ByteString> for Cow<'a, ByteStr> {
/// Wrap `ByteString` in `Cow::Owned`.
#[inline]
fn from(s: ByteString) -> Self {
Cow::Owned(s)
Expand All @@ -254,6 +258,7 @@ impl<'a> From<ByteString> 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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Wrap `ByteString` as byte str in `Cow::Borrowed`.

#[inline]
fn from(s: &'a ByteString) -> Self {
Cow::Borrowed(s.as_bytestr())
Expand Down Expand Up @@ -599,6 +604,7 @@ impl Clone for Box<ByteStr> {

#[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)
Expand All @@ -607,6 +613,7 @@ impl<'a> From<&'a ByteStr> for Cow<'a, ByteStr> {

#[unstable(feature = "bstr", issue = "134915")]
impl From<Box<[u8]>> for Box<ByteStr> {
/// Move the bytes from `Box<ByteStr>` to `Box<[u8]>`, this does not allocate new memory.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Move the bytes from `Box<ByteStr>` to `Box<[u8]>`, this does not allocate new memory.

#[inline]
fn from(s: Box<[u8]>) -> Box<ByteStr> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -616,6 +623,7 @@ impl From<Box<[u8]>> for Box<ByteStr> {

#[unstable(feature = "bstr", issue = "134915")]
impl From<Box<ByteStr>> for Box<[u8]> {
/// Convert the inner bytes of `Box<[u8]>` to `ByteStr`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Convert the inner bytes of `Box<[u8]>` to `ByteStr`.

#[inline]
fn from(s: Box<ByteStr>) -> Box<[u8]> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -626,6 +634,7 @@ impl From<Box<ByteStr>> for Box<[u8]> {
#[unstable(feature = "bstr", issue = "134915")]
#[cfg(not(no_rc))]
impl From<Rc<[u8]>> for Rc<ByteStr> {
/// Create an `Rc<[u8]>` from the inner bytes of `Rc<ByteStr>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create an `Rc<[u8]>` from the inner bytes of `Rc<ByteStr>`.

#[inline]
fn from(s: Rc<[u8]>) -> Rc<ByteStr> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -636,6 +645,7 @@ impl From<Rc<[u8]>> for Rc<ByteStr> {
#[unstable(feature = "bstr", issue = "134915")]
#[cfg(not(no_rc))]
impl From<Rc<ByteStr>> for Rc<[u8]> {
/// Create a `Rc<ByteStr>` from the bytes of `Rc<[u8]>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create a `Rc<ByteStr>` from the bytes of `Rc<[u8]>`.

#[inline]
fn from(s: Rc<ByteStr>) -> Rc<[u8]> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -646,6 +656,7 @@ impl From<Rc<ByteStr>> for Rc<[u8]> {
#[unstable(feature = "bstr", issue = "134915")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
impl From<Arc<[u8]>> for Arc<ByteStr> {
/// Create an `Arc<ByteStr>` from the bytes of `Arc<[u8]>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create an `Arc<ByteStr>` from the bytes of `Arc<[u8]>`.

#[inline]
fn from(s: Arc<[u8]>) -> Arc<ByteStr> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -656,6 +667,7 @@ impl From<Arc<[u8]>> for Arc<ByteStr> {
#[unstable(feature = "bstr", issue = "134915")]
#[cfg(all(not(no_rc), not(no_sync), target_has_atomic = "ptr"))]
impl From<Arc<ByteStr>> for Arc<[u8]> {
/// Create a `Arc<[u8]>` from the inner bytes of `Arc<ByteStr>`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create a `Arc<[u8]>` from the inner bytes of `Arc<ByteStr>`.

#[inline]
fn from(s: Arc<ByteStr>) -> Arc<[u8]> {
// SAFETY: `ByteStr` is a transparent wrapper around `[u8]`.
Expand All @@ -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
Comment on lines +690 to +693
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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<Self, Self::Error> {
Ok(core::str::from_utf8(&s.0)?.into())
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for VecDeque<T, A> {
/// [`Vec<T>`]: crate::vec::Vec
/// [`VecDeque<T>`]: 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.
Expand Down
16 changes: 4 additions & 12 deletions library/alloc/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ pub trait Wake {
#[cfg(target_has_atomic = "ptr")]
#[stable(feature = "wake_trait", since = "1.51.0")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> 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<W>) -> Waker {
// SAFETY: This is safe because raw_waker safely constructs
// a RawWaker from Arc<W>.
Expand All @@ -119,9 +117,7 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for Waker {
#[cfg(target_has_atomic = "ptr")]
#[stable(feature = "wake_trait", since = "1.51.0")]
impl<W: Wake + Send + Sync + 'static> From<Arc<W>> 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<W>) -> RawWaker {
raw_waker(waker)
}
Expand Down Expand Up @@ -286,9 +282,7 @@ pub trait LocalWake {

#[unstable(feature = "local_waker", issue = "118959")]
impl<W: LocalWake + 'static> From<Rc<W>> 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<W>) -> LocalWaker {
// SAFETY: This is safe because raw_waker safely constructs
// a RawWaker from Rc<W>.
Expand All @@ -298,9 +292,7 @@ impl<W: LocalWake + 'static> From<Rc<W>> for LocalWaker {
#[allow(ineffective_unstable_trait_impl)]
#[unstable(feature = "local_waker", issue = "118959")]
impl<W: LocalWake + 'static> From<Rc<W>> 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<W>) -> RawWaker {
local_raw_waker(waker)
}
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ascii/ascii_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ macro_rules! into_int_impl {
$(
#[unstable(feature = "ascii_char", issue = "110998")]
impl From<AsciiChar> for $ty {
#[doc = concat!("Convert `AsciiChar` as `u8` into `", stringify!($ty), "`")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[doc = concat!("Convert `AsciiChar` as `u8` into `", stringify!($ty), "`")]

#[inline]
fn from(chr: AsciiChar) -> $ty {
chr as u8 as $ty
Expand Down
1 change: 1 addition & 0 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ impl<T> From<NonZero<T>> for T
where
T: ZeroablePrimitive,
{
/// Returns the contained value as a primitive type.
#[inline]
fn from(nonzero: NonZero<T>) -> Self {
// Call `get` method to keep range information.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ impl<T: ?Sized> hash::Hash for NonNull<T> {

#[unstable(feature = "ptr_internals", issue = "none")]
impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
/// Cast `Unique` to a `NonNull`.
#[inline]
fn from(unique: Unique<T>) -> Self {
unique.as_non_null_ptr()
Expand Down
1 change: 1 addition & 0 deletions library/core/src/sync/exclusive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl<T: ?Sized> Exclusive<T> {

#[unstable(feature = "exclusive_wrapper", issue = "98407")]
impl<T> From<T> for Exclusive<T> {
/// Creates a new `Exclusive` wrapping `T`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Creates a new `Exclusive` wrapping `T`.

#[inline]
fn from(t: T) -> Self {
Self::new(t)
Expand Down
3 changes: 3 additions & 0 deletions library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ where
T: MaskElement,
LaneCount<N>: SupportedLaneCount,
{
/// Uses `from_array` to create a new `Mask`
#[inline]
fn from(array: [bool; N]) -> Self {
Self::from_array(array)
Expand All @@ -389,6 +390,7 @@ where
T: MaskElement,
LaneCount<N>: SupportedLaneCount,
{
/// Converts a SIMD mask to an array of bools.
#[inline]
fn from(vector: Mask<T, N>) -> Self {
vector.to_array()
Expand Down Expand Up @@ -634,6 +636,7 @@ macro_rules! impl_from {
where
LaneCount<N>: SupportedLaneCount,
{
/// Casts the value into the other `Mask`
#[inline]
fn from(value: Mask<$from, N>) -> Self {
value.cast()
Expand Down
1 change: 1 addition & 0 deletions library/portable-simd/crates/core_simd/src/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,7 @@ where
LaneCount<N>: SupportedLaneCount,
T: SimdElement,
{
/// Load the array into a new `Simd`
#[inline]
fn from(array: [T; N]) -> Self {
Self::from_array(array)
Expand Down
1 change: 1 addition & 0 deletions library/portable-simd/crates/core_simd/src/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), "`")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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
Expand Down
1 change: 1 addition & 0 deletions library/proc_macro/src/bridge/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ impl Drop for Buffer {
}

impl From<Vec<u8>> for Buffer {
/// Create a `Buffer` without allocation.
fn from(v: Vec<u8>) -> Self {
let mut v = ManuallyDrop::new(v);
let (data, len, capacity) = (v.as_mut_ptr(), v.len(), v.capacity());
Expand Down
1 change: 1 addition & 0 deletions library/proc_macro/src/bridge/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Create a `Closure` from an `FnMut` eg.(function, `||` closure)

fn from(f: &'a mut F) -> Self {
unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: *mut Env, arg: A) -> R {
unsafe { (*(env as *mut _ as *mut F))(arg) }
Expand Down
2 changes: 2 additions & 0 deletions library/proc_macro/src/bridge/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ pub enum PanicMessage {
}

impl From<Box<dyn Any + Send>> for PanicMessage {
/// Extract `String` or `&'static str` payloads if available or default to `Unknown`
fn from(payload: Box<dyn Any + Send + 'static>) -> Self {
if let Some(s) = payload.downcast_ref::<&'static str>() {
return PanicMessage::StaticStr(s);
Expand All @@ -265,6 +266,7 @@ impl From<Box<dyn Any + Send>> for PanicMessage {
}

impl From<PanicMessage> for Box<dyn Any + Send> {
/// Wrap the inner message in a newly allocated `Box`.
fn from(val: PanicMessage) -> Self {
match val {
PanicMessage::StaticStr(s) => Box::new(s),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ impl<E> From<E> for Report<E>
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 }
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/io/buffered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl<W> IntoInnerError<W> {

#[stable(feature = "rust1", since = "1.0.0")]
impl<W> From<IntoInnerError<W>> for Error {
/// Extracts the inner [`Error`]. Equivalent to [`into_error`](IntoInnerError::into_error).
fn from(iie: IntoInnerError<W>) -> Error {
iie.1
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/linux/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl From<OwnedFd> for PidFd {
}

impl From<PidFd> for OwnedFd {
/// Get the inner of `PidFd`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get the inner of `PidFd`

fn from(pid_fd: PidFd) -> Self {
pid_fd.into_inner().into_inner().into_inner()
}
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/os/solid/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ macro_rules! impl_owned_fd_traits {
}

impl From<net::$t> for OwnedFd {
#[doc = concat!("Create a `OwnedFd` from inner `", stringify!($t), "`")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[doc = concat!("Create a `OwnedFd` from inner `", stringify!($t), "`")]

#[inline]
fn from(socket: net::$t) -> OwnedFd {
socket.into_inner().into_socket().into_inner()
}
}

impl From<OwnedFd> for net::$t {
#[doc = concat!("Create a `", stringify!($t), "` with inner `OwnedFd`")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[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)))
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ impl From<UnixDatagram> for OwnedFd {

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for UnixDatagram {
/// Takes ownership of a [`OwnedFd`]'s socket file descriptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Takes ownership of a [`OwnedFd`]'s socket file descriptor.

#[inline]
fn from(owned: OwnedFd) -> Self {
unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ impl From<UnixStream> for OwnedFd {

#[stable(feature = "io_safety", since = "1.63.0")]
impl From<OwnedFd> for UnixStream {
/// Takes ownership of a [`OwnedFd`]'s socket file descriptor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Takes ownership of a [`OwnedFd`]'s socket file descriptor.

#[inline]
fn from(owned: OwnedFd) -> Self {
unsafe { Self::from_raw_fd(owned.into_raw_fd()) }
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/windows/io/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ impl<T> AsHandle for crate::thread::JoinHandle<T> {

#[stable(feature = "io_safety", since = "1.63.0")]
impl<T> From<crate::thread::JoinHandle<T>> for OwnedHandle {
/// Get the inner handle of `JoinHandle`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Get the inner handle of `JoinHandle`.

#[inline]
fn from(join_handle: crate::thread::JoinHandle<T>) -> OwnedHandle {
join_handle.into_inner().into_handle().into_inner()
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/os/xous/ffi/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum Error {

#[stable(feature = "rust1", since = "1.0.0")]
impl From<usize> for Error {
/// Convert an error code to an `Error`
fn from(src: usize) -> Self {
match src {
0 => Self::NoError,
Expand Down Expand Up @@ -115,6 +116,7 @@ impl From<usize> for Error {

#[stable(feature = "rust1", since = "1.0.0")]
impl From<i32> 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::<usize>::try_into(src) else {
return Self::UnknownError;
Expand Down Expand Up @@ -193,6 +195,7 @@ pub struct Connection(u32);

#[stable(feature = "rust1", since = "1.0.0")]
impl From<u32> for Connection {
/// Make a `Connection` with `u32` as inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Make a `Connection` with `u32` as inner

fn from(src: u32) -> Connection {
Connection(src)
}
Expand Down Expand Up @@ -263,6 +266,7 @@ impl Into<[u32; 4]> for ServerAddress {
pub(crate) struct ThreadId(usize);

impl From<usize> for ThreadId {
/// Make a `ThreadId` with `usize` as the id
fn from(src: usize) -> ThreadId {
ThreadId(src)
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,7 @@ impl ExitStatusError {

#[unstable(feature = "exit_status_error", issue = "84908")]
impl From<ExitStatusError> for ExitStatus {
/// Converts an `ExitStatusError` (back) to an `ExitStatus`.
fn from(error: ExitStatusError) -> Self {
Self(error.0.into())
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/mpmc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl<T> error::Error for SendTimeoutError<T> {}

#[unstable(feature = "mpmc_channel", issue = "126840")]
impl<T> From<SendError<T>> for SendTimeoutError<T> {
/// Wrap a `SendError` in the `Disconnected` variant.
fn from(err: SendError<T>) -> SendTimeoutError<T> {
match err {
SendError(e) => SendTimeoutError::Disconnected(e),
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/mpmc/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum Selected {
}

impl From<usize> for Selected {
/// Make a `Selected` from a `usize`, 0-2 match specific variants, the rest matches `Operation`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Make a `Selected` from a `usize`, 0-2 match specific variants, the rest matches `Operation`

#[inline]
fn from(val: usize) -> Selected {
match val {
Expand Down
Loading
Loading