mirror of https://github.com/rwf2/Rocket.git
Add 'Config::get_string' to retrieve 'String' from extras.
This commit is contained in:
parent
e8ada89197
commit
8de1e32130
|
@ -597,7 +597,7 @@ impl Config {
|
|||
self.secret_key.inner()
|
||||
}
|
||||
|
||||
/// Attempts to retrieve the extra named `name` as a string.
|
||||
/// Attempts to retrieve the extra named `name` as a borrowed string.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
|
@ -621,6 +621,29 @@ impl Config {
|
|||
val.as_str().ok_or_else(|| self.bad_type(name, val.type_str(), "a string"))
|
||||
}
|
||||
|
||||
/// Attempts to retrieve the extra named `name` as an owned string.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If an extra with `name` doesn't exist, returns an `Err` of `NotFound`.
|
||||
/// If an extra with `name` _does_ exist but is not a string, returns a
|
||||
/// `BadType` error.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use rocket::config::{Config, Environment};
|
||||
///
|
||||
/// let config = Config::build(Environment::Staging)
|
||||
/// .extra("my_extra", "extra_value")
|
||||
/// .unwrap();
|
||||
///
|
||||
/// assert_eq!(config.get_string("my_extra"), Ok("extra_value".to_string()));
|
||||
/// ```
|
||||
pub fn get_string(&self, name: &str) -> Result<String> {
|
||||
self.get_str(name).map(|s| s.to_string())
|
||||
}
|
||||
|
||||
/// Attempts to retrieve the extra named `name` as an integer.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
Loading…
Reference in New Issue