Skip to content

Commit 7c5dd9e

Browse files
Remove the second 'unset' generic argument from Optional
This is no longer needed with our new design. PiperOrigin-RevId: 653488903
1 parent be4f149 commit 7c5dd9e

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

rust/optional.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ use std::ptr;
2323
///
2424
/// Two `Optional`s are equal if they match both presence and the field values.
2525
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26-
pub enum Optional<SetVal, UnsetVal = SetVal> {
26+
pub enum Optional<T> {
2727
/// The field is set; it is present in the serialized message.
2828
///
2929
/// - For an `_opt()` accessor, this contains a `View<impl Proxied>`.
3030
/// - For a `_mut()` accessor, this contains a [`PresentField`] that can be
3131
/// used to access the current value, convert to [`Mut`], clear presence,
3232
/// or set a new value.
33-
Set(SetVal),
33+
Set(T),
3434

3535
/// The field is unset; it is absent in the serialized message.
3636
///
3737
/// - For an `_opt()` accessor, this contains a `View<impl Proxied>` with
3838
/// the default value.
3939
/// - For a `_mut()` accessor, this contains an [`AbsentField`] that can be
4040
/// used to access the default or set a new value.
41-
Unset(UnsetVal),
41+
Unset(T),
4242
}
4343

4444
impl<T> Optional<T> {
@@ -53,9 +53,7 @@ impl<T> Optional<T> {
5353
pub fn new(val: T, is_set: bool) -> Self {
5454
if is_set { Optional::Set(val) } else { Optional::Unset(val) }
5555
}
56-
}
5756

58-
impl<T, A> Optional<T, A> {
5957
/// Converts into an `Option` of the set value, ignoring any unset value.
6058
pub fn into_option(self) -> Option<T> {
6159
if let Optional::Set(x) = self { Some(x) } else { None }

rust/test/shared/accessors_test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,8 @@ fn test_singular_msg_field() {
609609
#[test]
610610
fn test_message_opt() {
611611
let msg = TestAllTypes::new();
612-
let opt: Optional<
613-
unittest_rust_proto::test_all_types::NestedMessageView<'_>,
614-
unittest_rust_proto::test_all_types::NestedMessageView<'_>,
615-
> = msg.optional_nested_message_opt();
612+
let opt: Optional<unittest_rust_proto::test_all_types::NestedMessageView<'_>> =
613+
msg.optional_nested_message_opt();
616614
assert_that!(opt.is_set(), eq(false));
617615
assert_that!(opt.into_inner().bb(), eq(0));
618616
}

0 commit comments

Comments
 (0)