@@ -86,13 +86,9 @@ compilePackage' package =
86
86
resolveWithModulePath :: ModulePath -> Maybe (BoundModule Rust )
87
87
resolveWithModulePath mp = resolveBoundModule mp package
88
88
modules' :: [RustModule ]
89
- modules' = libModule : [ RustModule { filePath = toFilePath $ toList mp
90
- , modPath = mp
91
- , children = childModules expanded' mp
92
- }
93
- | mp <- toList expanded' ]
89
+ modules' = libModule : map (toRustModule expanded') (toList expanded')
94
90
expanded' = hierarchies $ S. fromList $ MS. keys $ modules package
95
- libModule = RustModule { filePath = toFilePath [ ]
91
+ libModule = RustModule { filePath = toFilePath True [ " lib " ]
96
92
, modPath = [" lib" ]
97
93
, children = S. map root expanded'
98
94
}
@@ -102,11 +98,21 @@ childModules modPaths base = fromMaybe mempty $ getOption $ foldMap f modPaths
102
98
where
103
99
f = Option . fmap (S. singleton . root) . stripPrefix base
104
100
105
- toFilePath :: [I. Identifier ] -> FilePath
106
- toFilePath [] = joinPath [" src" , " lib.rs" ]
107
- toFilePath p = joinPath ([" src" ] ++ convert p ++ [" mod.rs" ])
101
+ toFilePath :: Bool -> ModulePath -> FilePath
102
+ toFilePath isLeaf p = joinPath (" src" : converted) ++ " .rs"
108
103
where
109
- convert = map (T. unpack . toRustIdentifier I. toSnakeCaseText)
104
+ convert = map (toRustIdentifier I. toSnakeCaseText) . toList
105
+ converted = map T. unpack $ convert p ++ (if isLeaf then [] else [" mod" ])
106
+
107
+ toRustModule :: Foldable f => f ModulePath -> ModulePath -> RustModule
108
+ toRustModule modPaths mp = RustModule { filePath = filePath'
109
+ , modPath = mp
110
+ , children = children'
111
+ }
112
+ where
113
+ children' = childModules modPaths mp
114
+ isLeaf = S. null children'
115
+ filePath' = toFilePath isLeaf mp
110
116
111
117
instance Target Rust where
112
118
type CompileResult Rust = Code
0 commit comments