Skip to content

Commit 4055998

Browse files
RobWaltgytic
andcommitted
docs(config): add link to snapshot method
We noticed that the docs around config are not as helpful yet as they could be. Newer rust users tend to assume that using `get_str` wouldn't be as hard to use and that it instead would work the same way as the other getters. This commit: - Adds a link to `snapshot` method documentation to provide additional guidance for newer Rust users. - Extends the error explanation with a vague reason to enhance understanding of the current behavior. Co-authored-by: gytic <149968794+gytic@users.noreply.github.com>
1 parent a2e05da commit 4055998

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/config.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,21 @@ impl Config {
237237
/// This is the same as `get_bytes` except that it may return `Err` if
238238
/// the bytes are not valid utf-8.
239239
///
240-
/// This method will return an error if this `Config` is not a snapshot.
240+
/// For consistency reasons, this method can only be called on a [`snapshot`].
241+
/// An error will be returned otherwise.
242+
///
243+
/// [`snapshot`]: `crate::Config::snapshot`
241244
pub fn get_str(&self, name: &str) -> Result<&str, Error> {
242245
str::from_utf8(self.get_bytes(name)?)
243246
.map_err(|_| Error::from_str("configuration value is not valid utf8"))
244247
}
245248

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

0 commit comments

Comments
 (0)