#[derive(partialeq,eq)是否会增加代码大小?
我提交了一个 /code> 因为我需要能够测试生成的故障。此补丁启用eq
和partialeq
,因此我可以使用assert_eq!()
测试故障。
问题是,
我的理解是,生成不必要的性状实现可以增加代码大小。
我的理解是,未使用的实现不会生成更多代码?这两个是正确的?
I submitted a patch to derive-builder
because I needed the ability to test failures generated. This patch enabled Eq
and PartialEq
so I could I test for failures using assert_eq!()
.
The question asked was,
My understanding is that generating unnecessary trait implementations can increase code size.
It is my understanding that implementations that are not used do not generate more code? Which of these two is correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我为测试该理论所做的,我生成了一个简单的二进制文件,
然后我进行了同一代一代,但是使用
#[derive(debug,partialeq,eq)]
。在这方面,我发现两者都产生了相同的哈希。他们是相同的。不具体,我还尝试创建库并使用- Release
编译。同样的事情。这次仅使用struct foo
(否main
)。在这种情况下,我确实观察到了差异,这是细微差别:rlib
是ar
chive。对我来说,它有三个文件,其中一个以cgu.0.rcgu.o.o
结尾是lib.rmeta
。*。O
文件完全相同(哈希)。lib.rmeta
文件在库中较大,该文件还衍生eq
和partialeq
。现在,至于 rmeta文档说这,
,似乎某些东西 变得更大,但是某物是只有用于工具目的。
我尝试了上面的测试,其中有和没有
pub
。我希望如果生成一个未使用的函数,它至少会导致一个.o
文件更大。不过,我无法观察到这一点。Here is what I did to test this theory, I generated a simple binary,
I then did the same generation but with
#[derive(Debug, PartialEq, Eq)]
. In this, I found both generated the same hash; they were identical. Not content, I also tried creating a library and compiling with--release
. Same thing. This time with juststruct Foo
(nomain
). In this case, I did observe a difference, here is the nuance:rlib
is anar
chive. For me it had three files, one of them ended incgu.0.rcgu.o
the other incgu.1.rcgu.o
, and there was one file that waslib.rmeta
.*.o
files were exactly the same (hashed).lib.rmeta
file was larger in the library that also derivedEq
, andPartialEq
.Now as to the merit of rmeta, the Rust documentation says this,
So it seems something gets bigger, but that something is ONLY used for tooling purposes.
I tried the above test with the library with and without
pub
. I would expect if a function was generated that wasn't used it would have at the least resulted in one.o
file being larger. I was not able to observe this though.