[][src]Struct rocket::config::ConfigBuilder

pub struct ConfigBuilder {
    pub environment: Environment,
    pub address: String,
    pub port: u16,
    pub workers: u16,
    pub keep_alive: u32,
    pub log_level: LoggingLevel,
    pub secret_key: Option<String>,
    pub tls: Option<(String, String)>,
    pub limits: Limits,
    pub extras: HashMap<String, Value>,
    pub root: Option<PathBuf>,
}

Structure following the builder pattern for building Config structures.

Fields

The environment that this configuration corresponds to.

The address to serve on.

The port to serve on.

The number of workers to run in parallel.

Keep-alive timeout in seconds or disabled if 0.

How much information to log.

The secret key.

TLS configuration (path to certificates file, path to private key file).

Size limits.

Any extra parameters that aren't part of Rocket's config.

The root directory of this config, if any.

Methods

impl ConfigBuilder
[src]

Create a new ConfigBuilder instance using the default parameters from the given environment.

This method is typically called indirectly via Config::build().

Example

use rocket::config::{Config, Environment};

let config = Config::build(Environment::Staging)
    .address("127.0.0.1")
    .port(700)
    .workers(12)
    .finalize();

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");

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);

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);

Sets the keep-alive timeout to timeout seconds. If timeout is 0, keep-alive is disabled.

Example

use rocket::config::{Config, Environment};

let config = Config::build(Environment::Staging)
    .keep_alive(10)
    .unwrap();

assert_eq!(config.keep_alive, Some(10));

let config = Config::build(Environment::Staging)
    .keep_alive(0)
    .unwrap();

assert_eq!(config.keep_alive, None);

Sets 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);

Sets 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();

Sets 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();

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();

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);

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().unwrap(), Path::new("/my_app/dir"));

Adds 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"));

Return the Config structure that was being built by this builder.

Errors

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)
    .keep_alive(0)
    .finalize();

assert!(config.is_ok());

let config = Config::build(Environment::Staging)
    .address("123.123.123.123.123 whoops!")
    .finalize();

assert!(config.is_err());

Return the Config structure that was being built by this builder.

Panics

Panics 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");

Returns the Config structure that was being built by this builder.

Panics

Panics 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]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for ConfigBuilder

impl Sync for ConfigBuilder

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> IntoCollection for T

impl<T, I> AsResult for T where
    I: Input,