Skip to content
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

docs(config): improve docs of Config::get_str/Config::get_bytes #1102

Merged
merged 1 commit into from
Nov 27, 2024
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
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,21 @@ impl Config {
/// This is the same as `get_bytes` except that it may return `Err` if
/// the bytes are not valid utf-8.
///
/// This method will return an error if this `Config` is not a snapshot.
/// For consistency reasons, this method can only be called on a [`snapshot`].
/// An error will be returned otherwise.
///
/// [`snapshot`]: `crate::Config::snapshot`
pub fn get_str(&self, name: &str) -> Result<&str, Error> {
str::from_utf8(self.get_bytes(name)?)
.map_err(|_| Error::from_str("configuration value is not valid utf8"))
}

/// Get the value of a string config variable as a byte slice.
///
/// This method will return an error if this `Config` is not a snapshot.
/// For consistency reasons, this method can only be called on a [`snapshot`].
/// An error will be returned otherwise.
///
/// [`snapshot`]: `crate::Config::snapshot`
pub fn get_bytes(&self, name: &str) -> Result<&[u8], Error> {
let mut ret = ptr::null();
let name = CString::new(name)?;
Expand Down