[Feature Request] Introduce Visibility to Struct
- Dominant language
- Rust
- Stars
- 378
- Forks
- 137
- PR merge metrics
- No merged PRs in 30d
Description
# 🚀 Feature Request
## Motivation
Currently, Move's structs use implicit visibility, e.g.
```rust
struct Foo{
f1: u64,
}
```
is equivalent to.
```rust
public struct Foo{
private f1: u64,
}
```
Also, an implicit global storage access restriction is used to ensure that a struct can only be borrowed in the module in which it is defined.
This is actually equivalent to a conditional visibility constraint and has the same effect as adding a private visibility constraint to the struct.
```rust
private struct Foo has key{
}
```
So I propose to introduce the visibility of structs. This leaves it up to the smart contract developer to decide on access control for the global storage and the struct fields.
For example.
```rust
module MyModule {
public struct Foo has key{
public f1:u64,
}
private struct Bar has key{
f1:u64,
}
public fun do_some(){
let foo = borrow_global();
let bar = borrow_global();
// Both of these work
}
}
module XXX {
use MyModule::Foo;
public fun so_some(){
let foo = borrow_global();
let f1 = foo.f1
let bar = borrow_global();
// the first one will succeed, the second one will fail
}
}
```
Of course, compatibility is a bigger problem, this is just an idea. If it works, I can do more work on it.
Contributor guide
Research direction
The issue names no files, tests, or entry points. Start by clarifying the proposed struct and field visibility rules, especially their interaction with global storage and compatibility; done requires an agreed design plus implementation and coverage for the resulting access behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- blockchain, compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100