Skip to content

RFC: Allow a module to export other items with same name #1738

@nikomatsakis

Description

@nikomatsakis

Right now, there is no convenient way to define a module like option, that both defines a type and several accessors. You end up defining a type t and then writing option::t, which is unfortunate. So unfortunate, it seems, that we hacked around this particular case in the core library.

Perhaps we could allow a special form of export that lets a module define the other namespaces associated with its name. So, for example, option could be defined as:

export t as mod;
enum t<A> { some(A), none }
fn foo() { ... }

Now if I do import option, the name option refers to the module option but also to the type option::t. You would be permitted one "as mod" export for each namespace other than module (values, types, impls?).

@pcwalton preferred as self as the syntax, but I don't think self is currently a keyword, so I substituted mod.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions