mirror of https://github.com/rwf2/Rocket.git
Use pub(crate) to enforce doc(hidden).
This commit is contained in:
parent
bf1b9e76fd
commit
aefa2f1494
|
@ -8,9 +8,8 @@ use rocket::config::Environment::*;
|
|||
fn init() {
|
||||
let cwd = env::current_dir().expect("current working directory");
|
||||
let tests_dir = cwd.join("tests");
|
||||
let config_dir = tests_dir.join("Rocket.toml");
|
||||
|
||||
let config = Config::default_for(Development, &config_dir).unwrap();
|
||||
let config = Config::build(Development).root(tests_dir).unwrap();
|
||||
rocket::custom(config, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,9 +96,9 @@ impl Catcher {
|
|||
Catcher { code: code, handler: handler, is_default: false }
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn handle<'r>(&self, err: Error, req: &'r Request) -> response::Result<'r> {
|
||||
pub(crate) fn handle<'r>(&self, err: Error, req: &'r Request)
|
||||
-> response::Result<'r> {
|
||||
(self.handler)(err, req)
|
||||
}
|
||||
|
||||
|
@ -107,9 +107,8 @@ impl Catcher {
|
|||
Catcher { code: code, handler: handler, is_default: true, }
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn is_default(&self) -> bool {
|
||||
pub(crate) fn is_default(&self) -> bool {
|
||||
self.is_default
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use config::{Result, Config, Value, Environment};
|
||||
use config::toml_ext::IntoValue;
|
||||
|
@ -21,6 +22,8 @@ pub struct ConfigBuilder {
|
|||
pub session_key: Option<String>,
|
||||
/// Any extra parameters that aren't part of Rocket's config.
|
||||
pub extras: HashMap<String, Value>,
|
||||
/// The root directory of this config.
|
||||
pub root: PathBuf,
|
||||
}
|
||||
|
||||
impl ConfigBuilder {
|
||||
|
@ -52,6 +55,7 @@ impl ConfigBuilder {
|
|||
let config = Config::new(environment)
|
||||
.expect("ConfigBuilder::new(): couldn't get current directory.");
|
||||
|
||||
let root_dir = PathBuf::from(config.root());
|
||||
ConfigBuilder {
|
||||
environment: config.environment,
|
||||
address: config.address,
|
||||
|
@ -60,6 +64,7 @@ impl ConfigBuilder {
|
|||
log_level: config.log_level,
|
||||
session_key: None,
|
||||
extras: config.extras,
|
||||
root: root_dir,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,6 +183,25 @@ impl ConfigBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the `root` in the configuration being built.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::path::Path;
|
||||
/// 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 root<P: AsRef<Path>>(mut self, path: P) -> Self {
|
||||
self.root = path.as_ref().to_path_buf();
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds an extra configuration parameter with `name` and `value` to the
|
||||
/// configuration being built. The value can be any type that implements
|
||||
/// [IntoValue](/config/trait.IntoValue.html) including `&str`, `String`,
|
||||
|
@ -236,6 +260,7 @@ impl ConfigBuilder {
|
|||
config.set_workers(self.workers);
|
||||
config.set_log_level(self.log_level);
|
||||
config.set_extras(self.extras);
|
||||
config.set_root(self.root);
|
||||
|
||||
if let Some(key) = self.session_key {
|
||||
config.set_session_key(key)?;
|
||||
|
|
|
@ -231,6 +231,27 @@ impl Config {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the root directory of this configuration to `root`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::path::Path;
|
||||
/// use rocket::config::{Config, Environment};
|
||||
///
|
||||
/// # use rocket::config::ConfigError;
|
||||
/// # fn config_test() -> Result<(), ConfigError> {
|
||||
/// let mut config = Config::new(Environment::Staging)?;
|
||||
/// config.set_root("/tmp/my_app");
|
||||
///
|
||||
/// assert_eq!(config.root(), Path::new("/tmp/my_app"));
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn set_root<P: AsRef<Path>>(&mut self, path: P) {
|
||||
self.config_path = path.as_ref().join("Rocket.custom.toml")
|
||||
}
|
||||
|
||||
/// Sets the address of `self` to `address`.
|
||||
///
|
||||
/// # Errors
|
||||
|
|
|
@ -33,15 +33,13 @@ impl Environment {
|
|||
}
|
||||
|
||||
/// Returns a string with a comma-seperated list of valid environments.
|
||||
#[doc(hidden)]
|
||||
pub fn valid() -> &'static str {
|
||||
pub(crate) fn valid() -> &'static str {
|
||||
"development, staging, production"
|
||||
}
|
||||
|
||||
/// Returns a list of all of the possible environments.
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
pub fn all() -> [Environment; 3] {
|
||||
pub(crate) fn all() -> [Environment; 3] {
|
||||
[Development, Staging, Production]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -420,8 +420,7 @@ impl RocketConfig {
|
|||
/// # Panics
|
||||
///
|
||||
/// If there is a problem, prints a nice error message and bails.
|
||||
#[doc(hidden)]
|
||||
pub fn init() -> (&'static Config, bool) {
|
||||
pub(crate) fn init() -> (&'static Config, bool) {
|
||||
let mut this_init = false;
|
||||
unsafe {
|
||||
INIT.call_once(|| {
|
||||
|
@ -433,8 +432,7 @@ pub fn init() -> (&'static Config, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn custom_init(config: Config) -> (&'static Config, bool) {
|
||||
pub(crate) fn custom_init(config: Config) -> (&'static Config, bool) {
|
||||
let mut this_init = false;
|
||||
|
||||
unsafe {
|
||||
|
|
|
@ -82,8 +82,7 @@ impl Data {
|
|||
DataStream::new(stream, network)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn from_hyp(mut h_body: BodyReader) -> Result<Data, &'static str> {
|
||||
pub(crate) fn from_hyp(mut h_body: BodyReader) -> Result<Data, &'static str> {
|
||||
// FIXME: This is asolutely terrible, thanks to Hyper.
|
||||
|
||||
// Retrieve the underlying HTTPStream from Hyper.
|
||||
|
@ -151,8 +150,7 @@ impl Data {
|
|||
// Creates a new data object with an internal buffer `buf`, where the cursor
|
||||
// in the buffer is at `pos` and the buffer has `cap` valid bytes. The
|
||||
// remainder of the data bytes can be read from `stream`.
|
||||
#[doc(hidden)]
|
||||
pub fn new(mut buf: Vec<u8>,
|
||||
pub(crate) fn new(mut buf: Vec<u8>,
|
||||
pos: usize,
|
||||
mut cap: usize,
|
||||
mut stream: StreamReader)
|
||||
|
|
|
@ -19,8 +19,7 @@ pub struct DataStream {
|
|||
}
|
||||
|
||||
impl DataStream {
|
||||
#[doc(hidden)]
|
||||
pub fn new(stream: InnerStream, network: HttpStream) -> DataStream {
|
||||
pub(crate) fn new(stream: InnerStream, network: HttpStream) -> DataStream {
|
||||
DataStream { stream: stream, network: network, }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,28 +40,27 @@ impl Data {
|
|||
DataStream { stream: BufReader::new(Cursor::new(self.data)) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn peek(&self) -> &[u8] {
|
||||
&self.data[..::std::cmp::min(PEEK_BYTES, self.data.len())]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn peek_complete(&self) -> bool {
|
||||
self.data.len() <= PEEK_BYTES
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn stream_to<W: Write>(self, writer: &mut W) -> io::Result<u64> {
|
||||
io::copy(&mut self.open(), writer)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn stream_to_file<P: AsRef<Path>>(self, path: P) -> io::Result<u64> {
|
||||
io::copy(&mut self.open(), &mut File::create(path)?)
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn from_hyp(mut h_body: BodyReader) -> Result<Data, &'static str> {
|
||||
pub(crate) fn from_hyp(mut h_body: BodyReader) -> Result<Data, &'static str> {
|
||||
let mut vec = Vec::new();
|
||||
if let Err(_) = io::copy(&mut h_body, &mut vec) {
|
||||
return Err("Reading from body failed.");
|
||||
|
@ -70,8 +69,7 @@ impl Data {
|
|||
Ok(Data::new(vec))
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn new(data: Vec<u8>) -> Data {
|
||||
pub(crate) fn new(data: Vec<u8>) -> Data {
|
||||
Data { data: data }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -502,9 +502,8 @@ impl<'h> HeaderMap<'h> {
|
|||
/// Consumes `self` and returns an iterator over all of the headers stored
|
||||
/// in the map in the way they are stored. This is a low-level machinism and
|
||||
/// should likely not be used.
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn into_iter_raw(self)
|
||||
#[inline]
|
||||
pub(crate) fn into_iter_raw(self)
|
||||
-> impl Iterator<Item=(UncasedAscii<'h>, Vec<Cow<'h, str>>)> {
|
||||
self.headers.into_iter()
|
||||
}
|
||||
|
|
|
@ -40,11 +40,6 @@ impl Method {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn to_hyp(&self) -> hyper::Method {
|
||||
self.to_string().as_str().parse().unwrap()
|
||||
}
|
||||
|
||||
/// Returns `true` ff an HTTP request with the method represented by `self`
|
||||
/// supports a payload.
|
||||
///
|
||||
|
|
|
@ -235,8 +235,8 @@ impl Status {
|
|||
/// Returns a status from a given status code. If the status code is a
|
||||
/// standard code, then the reason phrase is populated accordingly.
|
||||
/// Otherwise the reason phrase is set to "<unknown code>".
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
pub fn raw(code: u16) -> Status {
|
||||
match Status::from_code(code) {
|
||||
Some(status) => status,
|
||||
|
|
|
@ -124,7 +124,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Success(10);
|
||||
/// assert_eq!(x.unwrap(), 10);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn unwrap(self) -> S {
|
||||
match self {
|
||||
Success(val) => val,
|
||||
|
@ -147,7 +147,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Success(10);
|
||||
/// assert_eq!(x.expect("success value"), 10);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn expect(self, message: &str) -> S {
|
||||
match self {
|
||||
Success(val) => val,
|
||||
|
@ -172,7 +172,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.is_success(), false);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn is_success(&self) -> bool {
|
||||
match *self {
|
||||
Success(_) => true,
|
||||
|
@ -197,7 +197,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.is_failure(), false);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn is_failure(&self) -> bool {
|
||||
match *self {
|
||||
Failure(_) => true,
|
||||
|
@ -222,7 +222,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.is_forward(), true);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn is_forward(&self) -> bool {
|
||||
match *self {
|
||||
Forward(_) => true,
|
||||
|
@ -248,7 +248,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.succeeded(), None);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn succeeded(self) -> Option<S> {
|
||||
match self {
|
||||
Success(val) => Some(val),
|
||||
|
@ -274,7 +274,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.failed(), None);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn failed(self) -> Option<E> {
|
||||
match self {
|
||||
Failure(val) => Some(val),
|
||||
|
@ -300,7 +300,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Forward(25);
|
||||
/// assert_eq!(x.forwarded(), Some(25));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn forwarded(self) -> Option<F> {
|
||||
match self {
|
||||
Forward(val) => Some(val),
|
||||
|
@ -320,7 +320,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
/// let x: Outcome<i32, &str, usize> = Failure("Hi! I'm an error.");
|
||||
/// assert_eq!(x.as_ref(), Failure(&"Hi! I'm an error."));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn as_ref(&self) -> Outcome<&S, &E, &F> {
|
||||
match *self {
|
||||
Success(ref val) => Success(val),
|
||||
|
@ -342,7 +342,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
///
|
||||
/// assert_eq!(x.unwrap(), 20);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn as_mut(&mut self) -> Outcome<&mut S, &mut E, &mut F> {
|
||||
match *self {
|
||||
Success(ref mut val) => Success(val),
|
||||
|
@ -351,8 +351,7 @@ impl<S, E, F> Outcome<S, E, F> {
|
|||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
fn formatting(&self) -> (Color, &'static str) {
|
||||
match *self {
|
||||
Success(..) => (Green, "Success"),
|
||||
|
|
|
@ -257,9 +257,8 @@ impl<'r> Request<'r> {
|
|||
}
|
||||
|
||||
/// Replace all of the cookies in `self` with `cookies`.
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn set_cookies(&mut self, cookies: Cookies) {
|
||||
#[inline]
|
||||
pub(crate) fn set_cookies(&mut self, cookies: Cookies) {
|
||||
self.cookies = cookies;
|
||||
}
|
||||
|
||||
|
@ -315,9 +314,8 @@ impl<'r> Request<'r> {
|
|||
/// was `route`. This should only be used internally by `Rocket` as improper
|
||||
/// use may result in out of bounds indexing.
|
||||
/// TODO: Figure out the mount path from here.
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn set_params(&self, route: &Route) {
|
||||
#[inline]
|
||||
pub(crate) fn set_params(&self, route: &Route) {
|
||||
*self.params.borrow_mut() = route.get_param_indexes(self.uri());
|
||||
}
|
||||
|
||||
|
@ -386,24 +384,23 @@ impl<'r> Request<'r> {
|
|||
}
|
||||
|
||||
/// Get the managed state container, if it exists. For internal use only!
|
||||
#[doc(hidden)]
|
||||
pub fn get_state(&self) -> Option<&'r Container> {
|
||||
#[inline]
|
||||
pub(crate) fn get_state(&self) -> Option<&'r Container> {
|
||||
self.state
|
||||
}
|
||||
|
||||
/// Set the state. For internal use only!
|
||||
#[doc(hidden)]
|
||||
pub fn set_state(&mut self, state: &'r Container) {
|
||||
#[inline]
|
||||
pub(crate) fn set_state(&mut self, state: &'r Container) {
|
||||
self.state = Some(state);
|
||||
}
|
||||
|
||||
/// Convert from Hyper types into a Rocket Request.
|
||||
#[doc(hidden)]
|
||||
pub fn from_hyp(h_method: hyper::Method,
|
||||
h_headers: hyper::header::Headers,
|
||||
h_uri: hyper::RequestUri,
|
||||
h_addr: SocketAddr,
|
||||
) -> Result<Request<'r>, String> {
|
||||
pub(crate) fn from_hyp(h_method: hyper::Method,
|
||||
h_headers: hyper::header::Headers,
|
||||
h_uri: hyper::RequestUri,
|
||||
h_addr: SocketAddr,
|
||||
) -> Result<Request<'r>, String> {
|
||||
// Get a copy of the URI for later use.
|
||||
let uri = match h_uri {
|
||||
hyper::RequestUri::AbsolutePath(s) => s,
|
||||
|
|
|
@ -876,9 +876,8 @@ impl<'r> Response<'r> {
|
|||
|
||||
// Makes the `Read`er in the body empty but leaves the size of the body if
|
||||
// it exists. Only meant to be used to handle HEAD requests automatically.
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn strip_body(&mut self) {
|
||||
pub(crate) fn strip_body(&mut self) {
|
||||
if let Some(body) = self.take_body() {
|
||||
self.body = match body {
|
||||
Body::Sized(_, n) => Some(Body::Sized(Box::new(io::empty()), n)),
|
||||
|
|
|
@ -176,9 +176,8 @@ impl Rocket {
|
|||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn dispatch<'s, 'r>(&'s self, request: &'r mut Request<'s>, data: Data)
|
||||
#[inline]
|
||||
pub(crate) fn dispatch<'s, 'r>(&'s self, request: &'r mut Request<'s>, data: Data)
|
||||
-> Response<'r> {
|
||||
info!("{}:", request);
|
||||
|
||||
|
@ -229,9 +228,8 @@ impl Rocket {
|
|||
/// until one of the handlers returns success or failure, or there are no
|
||||
/// additional routes to try (forward). The corresponding outcome for each
|
||||
/// condition is returned.
|
||||
#[doc(hidden)]
|
||||
#[inline(always)]
|
||||
pub fn route<'r>(&self, request: &'r Request, mut data: Data)
|
||||
#[inline]
|
||||
pub(crate) fn route<'r>(&self, request: &'r Request, mut data: Data)
|
||||
-> handler::Outcome<'r> {
|
||||
// Go through the list of matching routes until we fail or succeed.
|
||||
let matches = self.router.route(request);
|
||||
|
@ -258,8 +256,7 @@ impl Rocket {
|
|||
}
|
||||
|
||||
// TODO: DOC.
|
||||
#[doc(hidden)]
|
||||
pub fn handle_error<'r>(&self, status: Status, req: &'r Request) -> Response<'r> {
|
||||
fn handle_error<'r>(&self, status: Status, req: &'r Request) -> Response<'r> {
|
||||
warn_!("Responding with {} catcher.", Red.paint(&status));
|
||||
|
||||
// Try to get the active catcher but fallback to user's 500 catcher.
|
||||
|
|
|
@ -70,8 +70,7 @@ impl Route {
|
|||
// TODO: Don't return a Vec...take in an &mut [&'a str] (no alloc!)
|
||||
/// Given a URI, returns a vector of slices of that URI corresponding to the
|
||||
/// dynamic segments in this route.
|
||||
#[doc(hidden)]
|
||||
pub fn get_param_indexes(&self, uri: &URI) -> Vec<(usize, usize)> {
|
||||
pub(crate) fn get_param_indexes(&self, uri: &URI) -> Vec<(usize, usize)> {
|
||||
let route_segs = self.path.segments();
|
||||
let uri_segs = uri.segments();
|
||||
let start_addr = uri.path().as_ptr() as usize;
|
||||
|
|
Loading…
Reference in New Issue