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

Message field design #520

Closed
Tracked by #518
stepancheg opened this issue Aug 12, 2020 · 0 comments
Closed
Tracked by #518

Message field design #520

stepancheg opened this issue Aug 12, 2020 · 0 comments
Labels
rust-protobuf-v3 Issued to be fixed to release version 3

Comments

@stepancheg
Copy link
Owner

Message fields should be stored as:

message_field: Option<Box<MyMessage>>

However, it is not convenient to work with data types like this:

  • obtaining a message or default value is inconvenient
  • assignment is inconvenient either

Current design for version 3 is to have MesssageField<T> data type:

struct MessageField<M: Message>(pub Option<Box<M>>);

impl<M: Message> MessageField {
  fn get_or_default(&self) -> &M {
    match &self.0 {
      Some(m) => m,
      None => M::default_instance(),
    }
  }
}

message_field: MessageField<MyMessage>,
@stepancheg stepancheg added the rust-protobuf-v3 Issued to be fixed to release version 3 label Aug 12, 2020
@stepancheg stepancheg mentioned this issue Aug 12, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust-protobuf-v3 Issued to be fixed to release version 3
Projects
None yet
Development

No branches or pull requests

1 participant