Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import macro from parent module [duplicate]

I'm having trouble re-using macros within a crate.

If a macro is defined in ./src/macros.rs:

#[macro_export]
macro_rules! my_macro {
    ...
}

and used in ./src/lib.rs:

#[macro_use]
pub mod macros;

I can't see this macro in ./src/submod/lib.rs:

my_macro!(...);

It yields the error message error: macro undefined: 'my_macro!'.

Is there a way I can import this macro in this child module submod?

like image 752
marcusklaas Avatar asked Jun 28 '15 18:06

marcusklaas


People also ask

How do I import a module from the parent directory?

As we have discussed earlier it is not possible to import a module from the parent directory, so this leads to an error something like this. File “C:/Users/sai mohan pulamolu/Desktop/parentdirectory/subdirectory/temp.py”, line 2, in <module> In order to import a module, the directory having that module must be present on PYTHONPATH.

How to import a module in Python?

In order to import a module, the directory having that module must be present on PYTHONPATH. It is an environment variable that contains the list of packages that will be loaded by Python. The list of packages presents in PYTHONPATH is also present in sys.path, so will add the parent directory path to the sys.path.

How to add parent directory to OS depending path?

You can use OS depending path in "module search path" which is listed in sys.path . So you can easily add parent directory like following import sys sys.path.insert (0,'..') sys.path.insert (0,'../..') This works both in python 2 and 3. Show activity on this post. Don't know much about python 2. import sys sys.path.append ('..')

How do I import code from one Excel workbook to another?

When you are ready to import it to another workbook, just right-click on the workbook you want to place it in and choose Import File…. Importing code modules or macros is as easy as that! You can use any of these options to copy code to your personal macro workbook as well.


1 Answers

I figured it out! It is imported automatically, but I didn't realize that macros are imported in order!

I imported the submod module before macros, so my_macro wasn't visible yet. By swapping the order, I got the expected behaviour.

like image 174
marcusklaas Avatar answered Oct 11 '22 12:10

marcusklaas