File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ pub struct Value(KString);
13
13
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
14
14
pub struct ValueRef < ' a > ( #[ cfg_attr( feature = "serde" , serde( borrow) ) ] KStringRef < ' a > ) ;
15
15
16
- /// Conversions
16
+ /// Lifecycle
17
17
impl < ' a > ValueRef < ' a > {
18
18
/// Keep `input` as our value.
19
19
pub fn from_bytes ( input : & ' a [ u8 ] ) -> Self {
@@ -25,7 +25,10 @@ impl<'a> ValueRef<'a> {
25
25
} ,
26
26
) )
27
27
}
28
+ }
28
29
30
+ /// Access and conversions
31
+ impl ValueRef < ' _ > {
29
32
/// Access this value as byte string.
30
33
pub fn as_bstr ( & self ) -> & BStr {
31
34
self . 0 . as_bytes ( ) . as_bstr ( )
@@ -79,6 +82,14 @@ impl StateRef<'_> {
79
82
pub fn is_unset ( & self ) -> bool {
80
83
matches ! ( self , StateRef :: Unset )
81
84
}
85
+
86
+ /// Attempt to obtain the string value of this state, or return `None` if there is no such value.
87
+ pub fn as_bstr ( & self ) -> Option < & BStr > {
88
+ match self {
89
+ StateRef :: Value ( v) => Some ( v. as_bstr ( ) ) ,
90
+ _ => None ,
91
+ }
92
+ }
82
93
}
83
94
84
95
/// Initialization
You can’t perform that action at this time.
0 commit comments