CopyPastor

Detecting plagiarism made easy.

Score: 0.8055140376091003; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2026-09-18
by plugwash

Original Post

Original - Posted on 2026-09-18
by plugwash



            
Present in both answers; Present only in the new answer; Present only in the old answer;

```as``` allows conversion between all of the primitive numeric types. It is "safe" in the sense that it will not violate memory safety or panic, but it may change the value. ```From``` on the other hand is only available for numeric types where the conversion will not change the value.
But that is only half the answer, unless you are doing embedded work you are most likely building for a 64-bit platform, where conversion from u64 to usize will not change the value. So why is there no ```From``` implementation. The issue has been discussed at least twice, the core concern being portability.
In 2016 [it was proposed](https://github.com/rust-lang/rust/pull/37423) to add the implementations with a "portability lint", but the proposal was not implemented, with someone suggesting to "hold off on this until we figure out where scenarios are going".
The issue was raised again in 2018 when the ```TryFrom``` trait [was stabilised](https://github.com/rust-lang/rust/pull/49305). Conversions from ```u16``` to ```usize``` and from ```u8``` and ```i16``` to ```isize```. These conversions were justified on the grounds that the C99 standard "(indirectly) requires pointers to be at least 16 bits.".
The submitter of the PR chose not to make any assumptions about the maximum size of pointers. He describes this decision as "conservative" and links to a poster and paper from the "cheri" project, some variants of which involve 256 bit pointers.
The existence of ```TryFrom``` raised a new problem with the possibility of implementing the ```From``` trait with a portability lint. There is a blanket implementation ```impl<T, U> TryFrom<U> for T where U: Into<T>,```. So implementing From conditionally would mean that the return type of try_from would vary between platforms. It would be difficult to implment a portability lint that could distinguish between usage of the ```TryFrom``` that depended on the ```Error``` type and usage that did not.
It was decided to remove the ```TryFrom``` implementations for ```usize``` so that stabilisation or ```TryFrom``` could go ahead without resolving the question of whether conditional ```From``` implementations should exist, but that quickly brought complaints from users and discussion was [moved to a new issue](https://github.com/rust-lang/rust/issues/49415) and [pr](https://github.com/rust-lang/rust/pull/51564).
In the end the option of having ```TryFrom``` implementations for ```usize``` that were consistent on all platforms (including potential future ones) won out over having ```From``` implementations for usize that were platform gated.
> As far as I know, usize is an integral type
True
> and those are never larger than 128 bits.
True today, but adding a new integer type would be a backwards-compatible change.
> why doesn't u128 implement From<usize>?
The issue has been discussed at least twice, the core concern being portability. Conversions to and from usize may be infallible on one architecture but fallible on other.
In 2016 [it was proposed](https://github.com/rust-lang/rust/pull/37423) to add the implementations with a "portability lint", but the proposal was not implemented, with someone suggesting to "hold off on this until we figure out where scenarios are going".
The issue was raised again in 2018 when the ```TryFrom``` trait [was stabilised](https://github.com/rust-lang/rust/pull/49305). Conversions from ```u16``` to ```usize``` and from ```u8``` and ```i16``` to ```isize```. These conversions were justified on the grounds that the C99 standard "(indirectly) requires pointers to be at least 16 bits.".
The submitter of the PR chose not to make any assumptions about the maximum size of pointers. He describes this decision as "conservative" and links to a poster and paper from the "cheri" project, some variants of which involve 256 bit pointers.
The existence of ```TryFrom``` raised a new problem with the possibility of implementing the ```From``` trait with a portability lint. There is a blanket implementation ```impl<T, U> TryFrom<U> for T where U: Into<T>,```. So implementing From conditionally would mean that the return type of try_from would vary between platforms. It would be difficult to implment a portability lint that could distinguish between usage of the ```TryFrom``` that depended on the ```Error``` type and usage that did not.
It was decided to remove the ```TryFrom``` implementations for ```usize``` so that stabilisation or ```TryFrom``` could go ahead without resolving the question of whether conditional ```From``` implementations should exist, but that quickly brought complaints from users and discussion was [moved to a new issue](https://github.com/rust-lang/rust/issues/49415) and [pr](https://github.com/rust-lang/rust/pull/51564).
In the end the option of having ```TryFrom``` implementations for ```usize``` that were consistent on all platforms (including potential future ones) won out over having ```From``` implementations for usize that were platform gated.

        
Present in both answers; Present only in the new answer; Present only in the old answer;