如何从Rust模块中获取公共元素?(How can I get the public elements from a Rust module?)

编程入门 行业动态 更新时间:2024-10-28 21:16:53
如何从Rust模块中获取公共元素?(How can I get the public elements from a Rust module?)

在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.

更多推荐

本文发布于:2023-07-08 01:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   元素   Rust   module   elements

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!