Title: I&#x27;ll preface this by saying I like Rust, and I&#x27;ve found myself coding more in Rust the last two years than anything else. But Rustaceans kind of like to laugh at Go, because it&#x27;s not as expressive or elegant a language by comparison. That&#x27;s mostly true, think of how nicely Option types, enums, and iterators work in Rust compared to Go. However, Go is simple and deeply pragmatic. There is an underrated value in that. Some parts of Rust are starting to remind me of the horror I ran from with C++. Look at this:<p>Update: It is possible to abuse existing CoerceUnsized implementations on stable. See #85099 (although I created that issue before reading any of this issue and its IRLO thread, so don’t expect any syntactic similarity to the unsoundness examples of this issue).<p>The type Pin&lt;&amp;LocalType&gt; implements Deref&lt;Target = LocalType&gt; but it doesn’t implement DerefMut. The types Pin and &amp; are #[fundamental] so that an impl DerefMut for Pin&lt;&amp;LocalType&gt;&gt; is possible. You can use LocalType == SomeLocalStruct or LocalType == dyn LocalTrait and you can coerce Pin&lt;Pin&lt;&amp;SomeLocalStruct&gt;&gt; into Pin&lt;Pin&lt;&amp;dyn LocalTrait&gt;&gt;. (Indeed, two layers of Pin!!) This allows creating a pair of “smart pointers that implement CoerceUnsized but have strange behavior” on stable (Pin&lt;&amp;SomeLocalStruct&gt; and Pin&lt;&amp;dyn LocalTrait&gt; become the smart pointers with “strange behavior” and they already implement CoerceUnsized).<p>More concretely: Since Pin&lt;&amp;dyn LocalTrait&gt;: Deref&lt;dyn LocalTrait&gt;, a “strange behavior” DerefMut implementation of Pin&lt;&amp;dyn LocalTrait&gt; can be used to dereference an underlying Pin&lt;&amp;SomeLocalStruct&gt; into, effectively, a target type (wrapped in the trait object) that’s different from SomeLocalStruct. The struct SomeLocalStruct might always be Unpin while the different type behind the &amp;mut dyn LocalTrait returned by DerefMut can be !Unpin. Having SomeLocalStruct: Unpin allows for easy creation of the Pin&lt;Pin&lt;&amp;SomeLocalStruct&gt;&gt; which coerces into Pin&lt;Pin&lt;&amp;dyn LocalTrait&gt;&gt; even though Pin&lt;&amp;dyn LocalTrait&gt;::Target: !Unpin (and even the actual Target type inside of the trait object being returned by the DerefMut can be !Unpin).<p>Methods on LocalTrait can be used both to make the DerefMut implementation possible and to convert the Pin&lt;&amp;mut dyn LocalTrait&gt; (from a Pin::as_mut call on &amp;mut Pin&lt;Pin&lt;&amp;dyn LocalTrait&gt;&gt;) back into a pinned mutable referene to the concrete “type behind the &amp;mut dyn LocalTrait returned by DerefMut”.<p>From: https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rust&#x2F;issues&#x2F;68015#issuecomment-835786438<p>Where&#x27;s that elegance now? I still maintain that I&#x27;d rather use Go when the problem domain allows for it (e.g. can use a garbage collector, don&#x27;t need fast interoperability with C, don&#x27;t need maximum performance.)
Upvote: