export_service! does not respect modules
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 301
- Forks
- 85
- Avg merge
- 1h 4m
- Merged PRs (30d)
- 4
Description
When I run this code:
mod my_module {
pub struct TestRecord {
id: String,
}
#[ic_cdk_macros::update]
fn test() -> TestRecord {
TestRecord {
id: "hello".to_string(),
}
}
}
I get these errors:
error[E0412]: cannot find type `TestRecord` in this scope
--> src/src/lib.rs:3192:1
|
3192 | candid::export_service!();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
= note: this error originates in the macro `candid::export_service` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
2 | use crate::my_module::TestRecord;
|
This is a minimally reproducible example of an issue we're running into in Azle (TypeScript CDK). A simple one-off solution is to add a fully qualified path to TestRecord in the method return type, such as crate::my_module::TestRecord. This is difficult for us to do in a generalized fashion for Azle though.
It would be ideal if the export_service! macro could fully handle methods defined within their own modules inside of the main canister crate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal Rust example and the candid::export_service! entry point shown in the issue, focusing on how module-defined methods and return types are resolved. Done means the macro handles methods inside nested modules without requiring fully qualified return-type paths, while preserving the exported service behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100