Struct rocket::config::Config [] [src]

pub struct Config {
    pub address: String,
    pub port: usize,
    pub log_level: LoggingLevel,
    pub env: Environment,
    // some fields omitted
}

The core configuration structure.

Fields

The address to serve on.

The port to serve on.

How much information to log.

The environment that this configuration corresponds to.

Methods

impl Config
[src]

Returns the default configuration for the environment env given that the configuration was stored at filepath. If filepath is not an absolute path, an Err of ConfigError::BadFilePath is returned.

Sets the configuration val for the name entry. If the name is one of "address", "port", "session_key", or "log" (the "default" values), the appropriate value in the self Config structure is set. Otherwise, the value is stored as an extra.

For each of the default values, the following Value variant is expected. If a different variant is supplied, a BadType Err is returned:

  • address: String
  • port: Integer
  • session_key: String (192-bit base64)
  • log: String

Moves the session key string out of the self Config, if there is one. Because the value is moved out, subsequent calls will result in a return value of None.

Example

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

// Create a new config with a session key.
let key = "adL5fFIPmZBrlyHk2YT4NLV3YCk2gFXz".to_string();
let config = Config::default_for(Environment::Staging, "/custom").unwrap()
    .session_key(key.clone());

// Get the key for the first time.
let session_key = config.take_session_key();
assert_eq!(session_key, Some(key.clone()));

// Try to get the key again.
let session_key_again = config.take_session_key();
assert_eq!(session_key_again, None);

Returns an iterator over the names and values of all of the extras in the self Config.

Attempts to retrieve the extra named name as a string. If an extra with that name doesn't exist, returns an Err of NotFound. If an extra with that name does exist but is not a string, returns a BadType error.

Attempts to retrieve the extra named name as an integer. If an extra with that name doesn't exist, returns an Err of NotFound. If an extra with that name does exist but is not an integer, returns a BadType error.

Attempts to retrieve the extra named name as a boolean. If an extra with that name doesn't exist, returns an Err of NotFound. If an extra with that name does exist but is not a boolean, returns a BadType error.

Attempts to retrieve the extra named name as a float. If an extra with that name doesn't exist, returns an Err of NotFound. If an extra with that name does exist but is not a float, returns a BadType error.

Returns the path at which the configuration file for self is stored. For instance, if the configuration file is at /tmp/Rocket.toml, the path /tmp is returned.

Sets the address in self to var and returns the structure.

Sets the port in self to var and returns the structure.

Sets the log_level in self to var and returns the structure.

Sets the session_key in self to var and returns the structure.

Sets the env in self to var and returns the structure.

Adds an extra configuration parameter with name and value to self and returns the structure.

Trait Implementations

impl Debug for Config
[src]

Formats the value using the given formatter.

impl PartialEq for Config
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.