Scala single method interface implementation

Scala has experimental support for SAMs starting with 2.11, under the flag -Xexperimental: Welcome to Scala version 2.11.0-RC3 (OpenJDK 64-Bit Server VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information. scala> :set -Xexperimental scala> val r: Runnable = () => println(“hello world”) r: Runnable = $anonfun$1@7861ff33 scala> new Thread(r).run … Read more

Can’t understand Rust module system

Short answer: you don’t need the mod phone in phone.rs. Just remove that and your code will work (assuming the rest of the code is correct). Longer answer: The following code in main.rs: pub mod phone; is equivalent to: pub mod phone { // literally insert the contents of phone.rs here } so you don’t … Read more

Traits vs. interfaces

Public Service Announcement: I want to state for the record that I believe traits are almost always a code smell and should be avoided in favor of composition. It’s my opinion that single inheritance is frequently abused to the point of being an anti-pattern and multiple inheritance only compounds this problem. You’ll be much better … Read more

Implement fmt::Display for Vec

As this error states, you cannot implement a trait for a type you don’t own: the impl does not reference any types defined in this crate; only traits defined in the current crate can be implemented for arbitrary types However, you can implement Display for your wrapper type. The piece you are missing is to … Read more