[−][src]Struct rocket::config::ConfigBuilder
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.
secret_key: Option<String>
The secret key.
tls: Option<(String, String)>
TLS configuration (path to certificates file, path to private key file).
limits: Limits
Size limits.
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]
impl ConfigBuilderpub fn new(environment: Environment) -> ConfigBuilder[src]
pub fn new(environment: Environment) -> ConfigBuilderCreate 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();
pub fn address<A: Into<String>>(self, address: A) -> Self[src]
pub fn address<A: Into<String>>(self, address: A) -> SelfSets 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");
pub fn port(self, port: u16) -> Self[src]
pub fn port(self, port: u16) -> SelfSets 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);
pub fn workers(self, workers: u16) -> Self[src]
pub fn workers(self, workers: u16) -> SelfSets 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);
pub fn log_level(self, log_level: LoggingLevel) -> Self[src]
pub fn log_level(self, log_level: LoggingLevel) -> SelfSets the log_level in the configuration being built.
Example
use rocket::config::{Config, Environment, LoggingLevel}; let config = Config::build(Environment::Staging) .log_level(LoggingLevel::Critical) .unwrap(); assert_eq!(config.log_level, LoggingLevel::Critical);
pub fn secret_key<K: Into<String>>(self, key: K) -> Self[src]
pub fn secret_key<K: Into<String>>(self, key: K) -> SelfSets the secret_key in the configuration being built.
Example
use rocket::config::{Config, Environment, LoggingLevel}; let key = "8Xui8SN4mI+7egV/9dlfYYLGQJeEx4+DwmSQLwDVXJg="; let mut config = Config::build(Environment::Staging) .secret_key(key) .unwrap();
pub fn limits(self, limits: Limits) -> Self[src]
pub fn limits(self, limits: Limits) -> SelfSets the limits in the configuration being built.
Example
use rocket::config::{Config, Environment, Limits}; let mut config = Config::build(Environment::Staging) .limits(Limits::new().limit("json", 5 * (1 << 20))) .unwrap();
pub fn tls<C, K>(self, certs_path: C, key_path: K) -> Self where
C: Into<String>,
K: Into<String>, [src]
pub fn tls<C, K>(self, certs_path: C, key_path: K) -> Self where
C: Into<String>,
K: Into<String>, Sets the TLS configuration in the configuration being built.
Certificates are read from certs_path. The certificate chain must be
in X.509 PEM format. The private key is read from key_path. The
private key must be an RSA key in either PKCS#1 or PKCS#8 PEM format.
Example
use rocket::config::{Config, Environment}; let mut config = Config::build(Environment::Staging) .tls("/path/to/certs.pem", "/path/to/key.pem") .unwrap();
pub fn environment(self, env: Environment) -> Self[src]
pub fn environment(self, env: Environment) -> SelfSets 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);
pub fn root<P: AsRef<Path>>(self, path: P) -> Self[src]
pub fn root<P: AsRef<Path>>(self, path: P) -> SelfSets 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"));
pub fn extra<V: Into<Value>>(self, name: &str, value: V) -> Self[src]
pub fn extra<V: Into<Value>>(self, name: &str, value: V) -> SelfAdds an extra configuration parameter with name and value to the
configuration being built. The value can be any type that implements
Into<Value> including &str, String, Vec<V: Into<Value>>,
HashMap<S: Into<String>, V: Into<Value>>, and most 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"));
pub fn finalize(self) -> Result<Config>[src]
pub 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 secret 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("123.123.123.123.123 whoops!") .finalize(); assert!(config.is_err());
pub fn unwrap(self) -> Config[src]
pub fn unwrap(self) -> ConfigReturn 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, secret key, or TLS configuration 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");
pub fn expect(self, msg: &str) -> Config[src]
pub fn expect(self, msg: &str) -> ConfigReturns 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, secret key, or TLS configuration fail to parse. If a
panic occurs, the error message msg is printed.
Example
use rocket::config::{Config, Environment}; let config = Config::build(Environment::Staging) .address("127.0.0.1") .expect("the configuration is bad!"); assert_eq!(config.address.as_str(), "127.0.0.1");
Trait Implementations
impl Clone for ConfigBuilder[src]
impl Clone for ConfigBuilderfn clone(&self) -> ConfigBuilder[src]
fn clone(&self) -> ConfigBuilderfn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
Auto Trait Implementations
impl Send for ConfigBuilder
impl Send for ConfigBuilderimpl Sync for ConfigBuilder
impl Sync for ConfigBuilderBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeIdimpl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut Timpl<T> Typeable for T where
T: Any, [src]
impl<T> Typeable for T where
T: Any,