Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String representation in FFI #2795

Closed
mversic opened this issue Sep 27, 2022 · 1 comment
Closed

String representation in FFI #2795

mversic opened this issue Sep 27, 2022 · 1 comment
Assignees
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST question Further information is requested

Comments

@mversic
Copy link
Contributor

mversic commented Sep 27, 2022

#2625 makes an assumption that String can be transmuted into Vec<u8>. Usually repr(Rust) structures don't offer any guarantees on the representation of the object in memory. However, this comment made some points in favor of making this assumption.

We should consider special handling String conversion in FFI instead of transmuting it into Vec<u8>

@mversic mversic added the iroha2-dev The re-implementation of a BFT hyperledger in RUST label Sep 27, 2022
@mversic mversic added the question Further information is requested label Sep 29, 2022
@Erigara Erigara self-assigned this Jan 12, 2023
@Erigara
Copy link
Contributor

Erigara commented Jan 12, 2023

After some investigation it was found that repr(rust) single-field structs is guaranteed to have the same memory layout as it's single field (Unsafe Code Guidelines Reference).

Currently String is implemented as single-field struct (source) so it's transmutable into Vec<u8>.
There is still chance that String layout will be changed in the future, but this seems unlikely and could be fixed later.

@Erigara Erigara closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iroha2-dev The re-implementation of a BFT hyperledger in RUST question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants