Commit ae4897a 1 parent 4ac87c7 commit ae4897a Copy full SHA for ae4897a
File tree 2 files changed +24
-0
lines changed
2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -451,6 +451,22 @@ impl Value {
451
451
self . as_buffer ( ) . is_some ( )
452
452
}
453
453
454
+ /// Returns `true` if the value is an [`Error`].
455
+ #[ inline]
456
+ pub fn is_error ( & self ) -> bool {
457
+ self . as_error ( ) . is_some ( )
458
+ }
459
+
460
+ /// Cast the value to [`Error`].
461
+ ///
462
+ /// If the value is an [`Error`], returns it or `None` otherwise.
463
+ pub fn as_error ( & self ) -> Option < & Error > {
464
+ match self {
465
+ Value :: Error ( e) => Some ( e) ,
466
+ _ => None ,
467
+ }
468
+ }
469
+
454
470
/// Wrap reference to this Value into [`SerializableValue`].
455
471
///
456
472
/// This allows customizing serialization behavior using serde.
Original file line number Diff line number Diff line change @@ -231,5 +231,13 @@ fn test_value_conversions() -> Result<()> {
231
231
Some ( & "hello" )
232
232
) ;
233
233
234
+ assert ! ( Value :: Error ( Box :: new( Error :: runtime( "some error" ) ) ) . is_error( ) ) ;
235
+ assert_eq ! (
236
+ ( Value :: Error ( Box :: new( Error :: runtime( "some error" ) ) ) . as_error( ) )
237
+ . unwrap( )
238
+ . to_string( ) ,
239
+ "runtime error: some error"
240
+ ) ;
241
+
234
242
Ok ( ( ) )
235
243
}
You can’t perform that action at this time.
0 commit comments