File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,35 @@ pub enum Optional<T> {
210
210
None ,
211
211
}
212
212
213
+ impl < T > Optional < T > {
214
+ /// Converts the `Optional` to an [`Option`].
215
+ pub fn into_option ( self ) -> Option < T > {
216
+ self . into ( )
217
+ }
218
+
219
+ /// Converts from `&Optional<T>` to `Option<&T>`.
220
+ ///
221
+ /// For convenience, this method directly performs the conversion to the standard
222
+ /// [`Option`] type.
223
+ pub const fn as_ref ( & self ) -> Option < & T > {
224
+ match self {
225
+ Self :: Some ( x) => Some ( x) ,
226
+ Self :: None => None ,
227
+ }
228
+ }
229
+
230
+ /// Converts from `&mut Optional<T>` to `Option<&mut T>`.
231
+ ///
232
+ /// For convenience, this method directly performs the conversion to the standard
233
+ /// [`Option`] type.
234
+ pub fn as_mut ( & mut self ) -> Option < & mut T > {
235
+ match self {
236
+ Self :: Some ( x) => Some ( x) ,
237
+ Self :: None => None ,
238
+ }
239
+ }
240
+ }
241
+
213
242
impl < T > From < Option < T > > for Optional < T > {
214
243
fn from ( v : Option < T > ) -> Self {
215
244
match v {
You can’t perform that action at this time.
0 commit comments