File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: encoding:: { DecodeContext , WireType } ;
2
- use crate :: { DecodeError , Message } ;
2
+ use crate :: { DecodeError , Message , UnknownEnumValue } ;
3
3
4
4
use bytes:: { Buf , BufMut } ;
5
5
@@ -128,6 +128,23 @@ impl<T> OpenEnum<T> {
128
128
}
129
129
}
130
130
131
+ /// If the value of the open enum is known, returns it in `Ok`, otherwise
132
+ /// returns an `Err` with the unknown value.
133
+ pub fn get ( & self ) -> Result < T , UnknownEnumValue >
134
+ where
135
+ T : Clone ,
136
+ {
137
+ match self {
138
+ Self :: Known ( v) => Ok ( v. clone ( ) ) ,
139
+ Self :: Unknown ( r) => Err ( UnknownEnumValue ( * r) ) ,
140
+ }
141
+ }
142
+
143
+ /// Sets the value of receiver to the provided known value.
144
+ pub fn set ( & mut self , value : T ) {
145
+ * self = Self :: Known ( value) ;
146
+ }
147
+
131
148
/// If the value of the open enum is known, returns it in `Some`, otherwise
132
149
/// returns `None`.
133
150
pub fn known ( self ) -> Option < T > {
You can’t perform that action at this time.
0 commit comments