-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In preparation for submodules in Mir this commit introduces structured module IDs. They are backwards-compatible with the old unstructured ones, which are considered to be identifiers of top-level modules. Signed-off-by: Matej Pavlovic <[email protected]>
- Loading branch information
1 parent
f89f005
commit 648968d
Showing
3 changed files
with
32 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package types | ||
|
||
import "strings" | ||
|
||
const Separator = "/" | ||
|
||
// ModuleID represents an identifier of a module. | ||
// It corresponds to a path in the module hierarchy. | ||
type ModuleID string | ||
|
||
// Pb converts a ModuleID to a type used in a Protobuf message. | ||
func (mid ModuleID) Pb() string { | ||
return string(mid) | ||
} | ||
|
||
// Top returns the ID of the top-level module of the path, stripped of the IDs of the submodules. | ||
func (mid ModuleID) Top() ModuleID { | ||
top, _, _ := strings.Cut(string(mid), Separator) | ||
return ModuleID(top) | ||
} | ||
|
||
// Sub returns the identifier of a submodule within the top-level module, stripped of the top-level module identifier. | ||
func (mid ModuleID) Sub() ModuleID { | ||
_, sub, _ := strings.Cut(string(mid), Separator) | ||
return ModuleID(sub) | ||
} | ||
|
||
// Then combines the module ID with a relative path to its submodule in a single module ID. | ||
func (mid ModuleID) Then(submodule ModuleID) ModuleID { | ||
return ModuleID(string(mid) + Separator + string(submodule)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters