In Rust, it seems you can basically put something in the main. Traits, implementation blocks, functions, static variables ...
For example, this compiles:
fn main() {
trait Foo {
fn foo();
}
impl Foo for f64 {
fn foo() {}
}
struct MyStruct;
enum RustIsCool {
MyStruct,
};
fn bar() {
trait Baz {
fn baz();
}
impl Baz for f64 {
fn baz() {}
}
}
static x: f64 = 10.0;
println!("This compiles!");
}
As you can see, you can even put these things inside other blocks.
Obviously, this is bad from a stylistic point of view; it's ugly, harder to refactor, and makes code reuse difficult.
But I'm curious: is there any overhead in terms of performance? Or does the Rust compiler optimize any differences?
source
share