在Node.js中,我可以在foo获取一个对象数组
Object.keys(require("foo"));有什么方法可以在Rust做同样的事情吗?
mod foo; getobjs(foo);In Node.js, I could get an array of the objects in foo with
Object.keys(require("foo"));Is there any way I could do the same thing in Rust?
mod foo; getobjs(foo);最满意答案
不,没有办法做到这一点。 编译时信息的这种内省级别在运行时根本不存在。 模块的概念甚至不存在。
如果您对编译时信息感兴趣,可以执行构建和查看文档( cargo doc --open )等操作,以查看整个箱子的所有公共项目。 您可以在使用之前在线查看包装箱的文档。
还有像Rust语言服务器这样的工具,它们为编辑器和IDE提供这种类型的信息(以及更多信息)。
No, there is no way to do this. This level of introspection of compile-time information simply doesn't exist at runtime. The concept of a module doesn't even exist.
If you are interested in compile-time information, you can do such things as build and view the docs (cargo doc --open) to see all the public items of the entire crate. You can probably also view the crate's documentation online before you use it.
There are also tools like the Rust Language Server which provide this type of information (and more) to editors and IDEs.
更多推荐
发布评论