Skip to content

Add support for non defined value in ConfigEntry #518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,30 @@ impl<'cfg> ConfigEntry<'cfg> {
/// Gets the value of this entry.
///
/// May return `None` if the value is not valid utf-8
///
/// # Panics
///
/// Panics when no value is defined.
pub fn value(&self) -> Option<&str> {
str::from_utf8(self.value_bytes()).ok()
}

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

/// Returns `true` when a value is defined otherwise `false`.
///
/// No value defined is a short-hand to represent a Boolean `true`.
pub fn has_value(&self) -> bool {
unsafe { !(*self.raw).value.is_null() }
}

/// Gets the configuration level of this entry.
pub fn level(&self) -> ConfigLevel {
unsafe { ConfigLevel::from_raw((*self.raw).level) }
Expand Down