Struct rocket::config::ConfigBuilder
[−]
[src]
pub struct ConfigBuilder { pub environment: Environment, pub address: String, pub port: u16, pub workers: u16, pub log_level: LoggingLevel, pub session_key: Option<String>, pub extras: HashMap<String, Value>, pub root: PathBuf, }
Structure following the builder pattern for building Config
structures.
Fields
environment: Environment
The environment that this configuration corresponds to.
address: String
The address to serve on.
port: u16
The port to serve on.
workers: u16
The number of workers to run in parallel.
log_level: LoggingLevel
How much information to log.
session_key: Option<String>
The session key.
extras: HashMap<String, Value>
Any extra parameters that aren't part of Rocket's config.
root: PathBuf
The root directory of this config.
Methods
impl ConfigBuilder
[src]
fn new(environment: Environment) -> ConfigBuilder
Create a new ConfigBuilder
instance using the default parameters from
the given environment
. The root configuration directory is set to the
current working directory.
This method is typically called indirectly via Config::build.
Panics
Panics if the current directory cannot be retrieved.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .address("127.0.0.1") .port(700) .workers(12) .finalize();
fn address<A: Into<String>>(self, address: A) -> Self
Sets the address
in the configuration being built.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .address("127.0.0.1") .unwrap(); assert_eq!(config.address.as_str(), "127.0.0.1");
fn port(self, port: u16) -> Self
Sets the port
in the configuration being built.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .port(1329) .unwrap(); assert_eq!(config.port, 1329);
fn workers(self, workers: u16) -> Self
Sets workers
in the configuration being built.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .workers(64) .unwrap(); assert_eq!(config.workers, 64);
fn log_level(self, log_level: LoggingLevel) -> Self
Sets the log_level
in the configuration being built.
Example
use rocket::LoggingLevel; use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .log_level(LoggingLevel::Critical) .unwrap(); assert_eq!(config.log_level, LoggingLevel::Critical);
fn session_key<K: Into<String>>(self, key: K) -> Self
Sets the session_key
in the configuration being built.
Example
use rocket::LoggingLevel; use rocket::config::{Config, Environment}; let key = "VheMwXIBygSmOlZAhuWl2B+zgvTN3WW5"; let mut config = Config::build(Environment::Staging) .session_key(key) .unwrap(); assert_eq!(config.take_session_key(), Some(key.to_string()));
fn environment(self, env: Environment) -> Self
Sets the environment
in the configuration being built.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .environment(Environment::Production) .unwrap(); assert_eq!(config.environment, Environment::Production);
fn root<P: AsRef<Path>>(self, path: P) -> Self
Sets the root
in the configuration being built.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .root("/my_app/dir") .unwrap(); assert_eq!(config.root(), Path::new("/my_app/dir"));
fn extra<V: IntoValue>(self, name: &str, value: V) -> Self
Adds an extra configuration parameter with name
and value
to the
configuration being built. The value can be any type that implements
IntoValue including &str
,
String
, Vec<V: IntoValue>
, HashMap<S: Into<String>, V: IntoValue>
,
and all integer and float types.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .extra("pi", 3.14) .extra("custom_dir", "/a/b/c") .unwrap(); assert_eq!(config.get_float("pi"), Ok(3.14)); assert_eq!(config.get_str("custom_dir"), Ok("/a/b/c"));
fn finalize(self) -> Result<Config>
Return the Config
structure that was being built by this builder.
Errors
If the current working directory cannot be retrieved, returns a BadCWD
error. If the address or session key fail to parse, returns a BadType
error.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .address("127.0.0.1") .port(700) .workers(12) .finalize(); assert!(config.is_ok()); let config = Config::build(Environment::Staging) .address("?") .finalize(); assert!(config.is_err());
fn unwrap(self) -> Config
Return the Config
structure that was being built by this builder.
Panics
Panics if the current working directory cannot be retrieved or if the supplied address or session key fail to parse.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .address("127.0.0.1") .unwrap(); assert_eq!(config.address.as_str(), "127.0.0.1");
Trait Implementations
impl Clone for ConfigBuilder
[src]
fn clone(&self) -> ConfigBuilder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more