Remove the second 'unset' generic argument from Optional

This is no longer needed with our new design.

PiperOrigin-RevId: 653488903
pull/17511/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent be4f149abd
commit 7c5dd9ec64
  1. 8
      rust/optional.rs
  2. 6
      rust/test/shared/accessors_test.rs

@ -23,14 +23,14 @@ use std::ptr;
///
/// Two `Optional`s are equal if they match both presence and the field values.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Optional<SetVal, UnsetVal = SetVal> {
pub enum Optional<T> {
/// The field is set; it is present in the serialized message.
///
/// - For an `_opt()` accessor, this contains a `View<impl Proxied>`.
/// - For a `_mut()` accessor, this contains a [`PresentField`] that can be
/// used to access the current value, convert to [`Mut`], clear presence,
/// or set a new value.
Set(SetVal),
Set(T),
/// The field is unset; it is absent in the serialized message.
///
@ -38,7 +38,7 @@ pub enum Optional<SetVal, UnsetVal = SetVal> {
/// the default value.
/// - For a `_mut()` accessor, this contains an [`AbsentField`] that can be
/// used to access the default or set a new value.
Unset(UnsetVal),
Unset(T),
}
impl<T> Optional<T> {
@ -53,9 +53,7 @@ impl<T> Optional<T> {
pub fn new(val: T, is_set: bool) -> Self {
if is_set { Optional::Set(val) } else { Optional::Unset(val) }
}
}
impl<T, A> Optional<T, A> {
/// Converts into an `Option` of the set value, ignoring any unset value.
pub fn into_option(self) -> Option<T> {
if let Optional::Set(x) = self { Some(x) } else { None }

@ -609,10 +609,8 @@ fn test_singular_msg_field() {
#[test]
fn test_message_opt() {
let msg = TestAllTypes::new();
let opt: Optional<
unittest_rust_proto::test_all_types::NestedMessageView<'_>,
unittest_rust_proto::test_all_types::NestedMessageView<'_>,
> = msg.optional_nested_message_opt();
let opt: Optional<unittest_rust_proto::test_all_types::NestedMessageView<'_>> =
msg.optional_nested_message_opt();
assert_that!(opt.is_set(), eq(false));
assert_that!(opt.into_inner().bb(), eq(0));
}

Loading…
Cancel
Save