MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
6.16k stars 11.18k forks source link

Why is `crate::sui_types::id::UID::new` not `const`? #20137

Open jymchng opened 3 hours ago

jymchng commented 3 hours ago

https://github.com/MystenLabs/sui/blob/69d3653419174917d8ffe667f230609970f9a544/crates/sui-types/src/id.rs#L38

Issue: Why is crate::sui_types::id::UID::new not const?

It should be const fn because ObjectID and AccountAddress can be constructed in const context and UID is a wrapper around ObjectID, hence it must be able to be constructed in the const context.

Furthermore, it appears in crate::sui_types::coin::CoinMetadata struct, and since it is 'metadata', it should be able to be constructed in const context too!

jymchng commented 3 hours ago

@sblackshear @patrickkuo

stefan-mysten commented 37 minutes ago

@jymchng thanks for the question. It seems that this would be possible. Would you be willing to push up a PR? We'd be happy to review it.