diff --git a/rust/optional.rs b/rust/optional.rs index 1f5cb9ad46..221f4d9ed2 100644 --- a/rust/optional.rs +++ b/rust/optional.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 { +pub enum Optional { /// The field is set; it is present in the serialized message. /// /// - For an `_opt()` accessor, this contains a `View`. /// - 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 { /// 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 Optional { @@ -53,9 +53,7 @@ impl Optional { pub fn new(val: T, is_set: bool) -> Self { if is_set { Optional::Set(val) } else { Optional::Unset(val) } } -} -impl Optional { /// Converts into an `Option` of the set value, ignoring any unset value. pub fn into_option(self) -> Option { if let Optional::Set(x) = self { Some(x) } else { None } diff --git a/rust/test/shared/accessors_test.rs b/rust/test/shared/accessors_test.rs index f108c889c1..c0365b1d9e 100644 --- a/rust/test/shared/accessors_test.rs +++ b/rust/test/shared/accessors_test.rs @@ -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> = + msg.optional_nested_message_opt(); assert_that!(opt.is_set(), eq(false)); assert_that!(opt.into_inner().bb(), eq(0)); }