Rocket/lib/src/lib.rs

141 lines
4.2 KiB
Rust
Raw Normal View History

#![feature(specialization)]
#![feature(conservative_impl_trait)]
#![feature(drop_types_in_const)]
//! # Rocket - Core API Documentation
2016-09-30 04:44:27 +00:00
//!
//! Hello, and welcome to the core Rocket API documentation!
//!
//! This API documentation is highly technical and is purely a reference.
//! There's an [overview](https://rocket.rs/overview) of Rocket on the main site
//! as well as a [full, detailed guide](https://rocket.rs/guide). If you'd like
//! pointers on getting started, see the
2016-10-01 03:22:06 +00:00
//! [quickstart](https://rocket.rs/guide/quickstart) or [getting
//! started](https://rocket.rs/guide/getting_started) chapters of the guide.
2016-09-30 04:44:27 +00:00
//!
//! You may also be interested in looking at the [contrib API
//! documentation](../rocket_contrib), which contains JSON and templating
2016-09-30 04:44:27 +00:00
//! support.
//!
//! ## Libraries
//!
//! Rocket's functionality is split into three crates:
//!
//! 1. [Core](/rocket) - The core library. Needed by every Rocket application.
//! 2. [Codegen](/rocket_codegen) - Core code generation plugin. Should always
//! be used alongsize `rocket`, though it's not necessary.
//! 3. [Contrib](/rocket_contrib) - Provides useful functionality for many
//! Rocket application. Completely optional.
//!
//! ## Usage
//!
//! The sanctioned way to use Rocket is via the code generation plugin. This
//! makes Rocket easier to use and allows a somewhat stable API as Rocket
//! matures. To use Rocket with the code generation plugin in your Cargo-based
//! project, add the following to `Cargo.toml`:
//!
//! ```rust,ignore
//! [dependencies]
//! rocket = "*"
//! rocket_codegen = "*"
//! ```
//!
//! If you'll be deploying your project to Crates.io, you'll need to change the
//! "*" to the current version of Rocket.
//!
//! Then, add the following to top of your `main.rs` file:
//!
2016-10-18 02:29:58 +00:00
//! ```rust
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//!
//! extern crate rocket;
//! ```
//!
2016-10-21 09:56:57 +00:00
//! See the [guide](https://rocket.rs/guide) for more information on how to
2016-10-18 02:29:58 +00:00
//! write Rocket applications. Here's a simple example to get you started:
//!
//! ```rust
//! #![feature(plugin)]
//! #![plugin(rocket_codegen)]
//!
//! extern crate rocket;
//!
//! #[get("/")]
//! fn hello() -> &'static str {
//! "Hello, world!"
//! }
//!
//! fn main() {
//! # if false { // We don't actually want to launch the server in an example.
//! rocket::ignite().mount("/", routes![hello]).launch()
//! # }
//! }
//! ```
//!
//! ## Configuration
//!
2016-10-18 02:29:58 +00:00
//! Rocket and Rocket libraries are configured via the `Rocket.toml` file. For
//! more information on how to configure Rocket, see the [configuration
//! section](/guide/configuration) of the guide as well as the [config](config)
//! module documentation.
//!
//! ## Testing
//!
//! Rocket includes a small testing library that can be used to test your Rocket
//! application. The library's API is unstable. For information on how to test
//! your Rocket applications, the [testing module](testing) documentation.
//!
#[macro_use] extern crate log;
extern crate term_painter;
extern crate hyper;
extern crate url;
extern crate toml;
#[cfg(test)] #[macro_use] extern crate lazy_static;
#[doc(hidden)] #[macro_use] pub mod logger;
#[cfg(any(test, feature = "testing"))] pub mod testing;
2016-10-08 11:29:20 +00:00
pub mod http;
pub mod request;
pub mod response;
pub mod outcome;
pub mod config;
mod error;
mod router;
mod rocket;
mod codegen;
mod catcher;
/// Defines the types for request and error handlers.
2016-10-08 11:42:22 +00:00
#[doc(hidden)]
pub mod handler {
use request::{Request, Data};
use response::Response;
use error::Error;
/// The type of a request handler.
pub type Handler = for<'r> fn(&'r Request, Data) -> Response<'r>;
/// The type of an error handler.
pub type ErrorHandler = for<'r> fn(Error, &'r Request) -> Response<'r>;
}
2016-10-08 11:42:22 +00:00
#[doc(inline)] pub use response::Response;
#[doc(inline)] pub use handler::{Handler, ErrorHandler};
#[doc(inline)] pub use logger::LoggingLevel;
2016-10-08 11:42:22 +00:00
#[doc(hidden)] pub use codegen::{StaticRouteInfo, StaticCatchInfo};
pub use router::Route;
pub use request::{Request, Data};
pub use error::Error;
pub use catcher::Catcher;
pub use rocket::Rocket;
pub use outcome::{Outcome, IntoOutcome};
/// Alias to Rocket::ignite().
pub fn ignite() -> Rocket {
Rocket::ignite()
}