graydon/rust — Issue #1241: Split Module Definitions
Author: DylanLukes
Created: 2011-12-01 13:59:50+00:00
State: open

Within the same *file and module*, modules should be able to be split up and combined at compile-time. This would allow putting non-native functions in a native module, in turn allowing convenient use of opaque forms. For example:

```rust
mod objc {
// Opaque type for objc objects. This might more realistically be a resource type to handle ObjC reference counting.
tag id { _id(unsafe::id) }

// safe version
fn get_class(name: str) -> id {
_id(str::as_buf(name, {|name_buf| unsafe::objc_getClass(name_buf)}))
}

mod unsafe {
// non-opaque type for objc objects
type void = int;
type cls = *void;
type id = *{isa: cls};
}
native mod unsafe {
fn objc_getClass(name: str::sbuf) -> id;
}
}
```