Skip to content

Commit 43b8e28

Browse files
authored
Add support for non defined value in ConfigEntry (#518)
1 parent 2c7b2c2 commit 43b8e28

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/config.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,15 +449,30 @@ impl<'cfg> ConfigEntry<'cfg> {
449449
/// Gets the value of this entry.
450450
///
451451
/// May return `None` if the value is not valid utf-8
452+
///
453+
/// # Panics
454+
///
455+
/// Panics when no value is defined.
452456
pub fn value(&self) -> Option<&str> {
453457
str::from_utf8(self.value_bytes()).ok()
454458
}
455459

456460
/// Gets the value of this entry as a byte slice.
461+
///
462+
/// # Panics
463+
///
464+
/// Panics when no value is defined.
457465
pub fn value_bytes(&self) -> &[u8] {
458466
unsafe { crate::opt_bytes(self, (*self.raw).value).unwrap() }
459467
}
460468

469+
/// Returns `true` when a value is defined otherwise `false`.
470+
///
471+
/// No value defined is a short-hand to represent a Boolean `true`.
472+
pub fn has_value(&self) -> bool {
473+
unsafe { !(*self.raw).value.is_null() }
474+
}
475+
461476
/// Gets the configuration level of this entry.
462477
pub fn level(&self) -> ConfigLevel {
463478
unsafe { ConfigLevel::from_raw((*self.raw).level) }

0 commit comments

Comments
 (0)