You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a number of high-profile crates in the Rust ecosystem that define types whose memory representation is part of their documented contract. By implementing zerocopy's traits for these types, their users could benefit from zerocopy's compiler-time checks that operations depending on these contracts are sound. But: Where should these trait implementations go?
It is risky for zerocopy to provide trait implementations on foreign types, since zerocopy cannot check the soundness of its implementations on foreign types. If zerocopy's trait implementations implementations on foreign types fell out of sync with the definitions of those types, unsoundness would ensue.
It is strictly safer for third-party types to provide their own implementations of zerocopy's traits, using zerocopy's derive feature. However, zerocopy is still a crate in active development, with occasional breaking changes. For greater interoperability in the ecosystem, we would like our public customers to track zerocopy's latest version. To do so, customers today must either:
document their zerocopy support as unstable
be willing to release new breaking changes of their crate, in step with zerocopy
Both of these options adds friction to the adoption of zerocopy in the Rust ecosystem.
Proposed Solution
There exists a third not-yet-quite-possible-today option: Provided multi-versioned support for zerocopy.
A customer taking this approach would specify a new optional dependency for each version of zerocopy they support; e.g., they would start with:
[dependencies]
zerocopy_0_7 = { package = "zerocopy", version = "0.7", optional = true, features = ["derive"] }
...and provide feature-gated implementations for that version:
Presently, zerocopy's derives unconditionally expand to code referencing the path ::zerocopy. This makes depending on multiple versions of zerocopy presently impossible, since they cannot all share that path. To support this approach, zerocopy can make one of two technical changes:
1. Root-setting helper attribute.
Zerocopy could provide a helper attribute for setting its crate root; e.g.:
There are a number of high-profile crates in the Rust ecosystem that define types whose memory representation is part of their documented contract. By implementing zerocopy's traits for these types, their users could benefit from zerocopy's compiler-time checks that operations depending on these contracts are sound. But: Where should these trait implementations go?
It is risky for zerocopy to provide trait implementations on foreign types, since zerocopy cannot check the soundness of its implementations on foreign types. If zerocopy's trait implementations implementations on foreign types fell out of sync with the definitions of those types, unsoundness would ensue.
It is strictly safer for third-party types to provide their own implementations of zerocopy's traits, using zerocopy's
derive
feature. However, zerocopy is still a crate in active development, with occasional breaking changes. For greater interoperability in the ecosystem, we would like our public customers to track zerocopy's latest version. To do so, customers today must either:Both of these options adds friction to the adoption of zerocopy in the Rust ecosystem.
Proposed Solution
There exists a third not-yet-quite-possible-today option: Provided multi-versioned support for zerocopy.
A customer taking this approach would specify a new optional dependency for each version of zerocopy they support; e.g., they would start with:
...and provide feature-gated implementations for that version:
Upon a new major release of zerocopy, the customer could append a new version to their
Cargo.toml
:[dependencies] zerocopy_0_7 = { package = "zerocopy", version = "0.7", optional = true, features = ["derive"] } + zerocopy_0_8 = { package = "zerocopy", version = "0.8", optional = true, features = ["derive"] }
...and add new, corresponding feature-gated derives:
Technical Details
Presently, zerocopy's derives unconditionally expand to code referencing the path
::zerocopy
. This makes depending on multiple versions of zerocopy presently impossible, since they cannot all share that path. To support this approach, zerocopy can make one of two technical changes:1. Root-setting helper attribute.
Zerocopy could provide a helper attribute for setting its crate root; e.g.:
The attribute would instruct zerocopy's derives to expand to paths beginning with
::zerocopy_0_7
, instead of::zerocopy
.The drawback of this approach is that this attribute adds line noise to critical derives.
2. Re-export old versions
Alternatively, zerocopy could optionally depend on older versions of itself:
...and provide versioned re-exports of itself at its root:
We would then modify zerocopy's derives to always expand to paths beginning with
::zerocopy::version::v_XXX
.Unresolved question: In this approach, how would we populate the
zerocopy
path on the consumer side?The text was updated successfully, but these errors were encountered: