Is it possible to use all the fns of an Enum/Struct?

I am trying:

use foobar_mod::FooBarStruct::*

however, it seems that I still have to call the static functions as FooBarStruct::some_static_func instead of just calling some_static_func

Question: is it possible to just import all the functions of an Enum/Struct ?

Yes and no. You can do this:

let bar = Foo::bar;
println!("{:?}", bar());


This doesn't quite work. I'm building a DSL, and have a Struct that has all the functions I want to use. I may just move this into a module instead.

When using a mod, you can definetely directly use pub functions defined in the mod, as long as you use the mod.
However, it seems that there's no such a concept of static functions in Rust. Methods of a struct are actually the same, I think. Methods with self, &self etc. are just a special case of other methods. So if you don't distinguish methods in such a way, the compiler won't know which methods you intend to use. For example, suppose we can do that, and we have Struct1 with new() and invoke(&self), Struct2 also with new() and invoke(&self). If we use both struct like this use Struct1::* and use Struct2::*, then when you write new(), which new() you intend to use?

1 Like

I would only do [quote="ifsheldon, post:4, topic:34352"]
If we use both struct like this use Struct1::* and use Struct2::* , then when you write new() , which new() you intend to use?

I wouldn't do this. I would only do:

use some_mod::MyDSL::*

However, I see how your question shows a problem with importing ::* from structs. Looks like it's best to just put everything in a mod instead.

Yes, it would be better. I think it is more like an improvement of namespaces in C++ without making things complex.