I would recommend reading about Rust's module system at
http://static.rust-lang.org/doc/master/tutorial.html#crates-and-the-module-system
to get more familiar with how things work.

You may also want to read about how import statements work at
http://static.rust-lang.org/doc/master/rust.html#use-declarations to
get an idea of how to bring these names into scope.

In rust's module system, you don't really load modules per-se, but
rather insert them at certain points in the namespace hierarchy. It's
perfectly valid to insert the same module at multiple locations in the
hierarchy, but I agree that this may not always have the expected
behavior. This probably warrants a lint mode for this which is warn by
default about inserting the same file into the module hierarchy twice,

On Fri, Nov 8, 2013 at 4:15 AM, Philippe Delrieu
<[email protected]> wrote:
> hanks for your fast answer.
> I've made some test and if I remove mod actions; in testaction.rs I have the
> error: unresolved name impl actions::Action for TestAction in testaction.rs
> If I remove the mod actions; and keep the mod testaction; in the test.rs I
> have unresolved name in the line let actelm: ~actions::Action = element as
> ~actions::Action; for actions::Action.
>
> I don't see what to do!!
>
> I didn't fully understand the module management but even if I made something
> wrong rustc in my opinion shouldn't load the same module twice and if a
> module is load once it should use it for all. It make me think about
> I#ifndef in C.
>
> Philippe Delrieu
>
>
> Le 08/11/2013 09:53, Alex Crichton a écrit :
>>
>> You should be careful to declare modules only once. It looks like you
>>
>> have two instances of "mod actions" in the module hierarchy, and both
>> modules will be compiled as separate entities (although everything
>> will have the same name).
>>
>> If you remove the `mod actions` inside of testaction.rs you should
>> start making some more progress. You'll probably hit some name
>> resolution issues, but just be sure to import the previous declaration
>> of the `actions` module in the top level of the crate.
>>
>> On Thu, Nov 7, 2013 at 11:50 PM, Philippe Delrieu
>> <[email protected]> wrote:
>>>
>>> Hello, rust addict.
>>>
>>> I have a problem with rustc. I have 3 files.
>>> The first one actions.rs contains a trait declaration :
>>>
>>> pub trait Action {
>>>      // process the action on server side.
>>>      fn process(&self) -> ~str;
>>> }
>>>
>>> The second contains a trait implementation testaction.rs:
>>> mod actions;
>>>
>>>
>>> pub struct TestAction    {
>>>      actiontype: uint
>>> }
>>>
>>> impl actions::Action for TestAction    {
>>>
>>>      fn process(&self) -> ~str     {
>>>          ~""
>>>      }
>>> }
>>>   The third test the trait cast :
>>>      mod actions;
>>>      mod midi;
>>>
>>>                  let element : ~testaction::TestAction =
>>> ~testaction::TestAction{actiontype:1};
>>>                  let actelm: ~actions::Action = element as
>>> ~actions::Action;
>>> //error here
>>>                  println("process element :" + actelm.process());
>>> => generate  error: failed to find an implementation of trait
>>>
>>>                  let actelm: ~testaction::actions::Action = element as
>>> ~testaction::actions::Action;  //error here
>>>                  println("process element :" + actelm.process());
>>> => generate error: trait `Action` is inaccessible
>>>
>>> If I put testaction content in the test file rustc compile.
>>>
>>> Any idea?
>>>
>>> Philippe Delrieu
>>>
>>>
>>> _______________________________________________
>>> Rust-dev mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to