cot/lib.rs
1//! Cot is an easy to use, modern, and fast web framework for Rust. It has
2//! been designed to be familiar if you've ever used
3//! [Django](https://www.djangoproject.com/), and easy to learn if you haven't.
4//! It's a batteries-included framework built on top of
5//! [axum](https://github.com/tokio-rs/axum).
6//!
7//! ## Features
8//!
9//! * **Easy to use API** — in many ways modeled after Django, Cot's API is
10//! designed to be easy to use and intuitive. Sensible defaults make it for
11//! easy rapid development, while the API is still empowering you when needed.
12//! The documentation is a first-class citizen in Cot, making it easy to find
13//! what you're looking for.
14//! * **ORM integration** — Cot comes with its own ORM, allowing you to interact
15//! with your database in a way that feels Rusty and intuitive. Rust types are
16//! the source of truth, and the ORM takes care of translating them to and
17//! from the database, as well as creating the migrations automatically.
18//! * **Type safe** — wherever possible, Cot uses Rust's type system to prevent
19//! common mistakes and bugs. Not only views are taking advantage of the
20//! Rust's type system, but also the ORM, the admin panel, and even the
21//! templates. All that to catch errors as early as possible.
22//! * **Admin panel** — Cot comes with an admin panel out of the box, allowing
23//! you to manage your app's data with ease. Adding new models to the admin
24//! panel is stupidly simple, making it a great tool not only for rapid
25//! development and debugging, but with its customization options, also for
26//! production use.
27//! * **Secure by default** — security should be opt-out, not opt-in. Cot takes
28//! care of making your web apps secure by default, defending it against
29//! common modern web vulnerabilities. You can focus on building your app, not
30//! securing it.
31//!
32//! ## Guide
33//!
34//! This is an API reference for Cot, which might not be the best place to
35//! start learning Cot. For a more gentle introduction, see the
36//! [Cot guide](https://cot.rs/guide/latest/).
37//!
38//! ## Examples
39//!
40//! To see examples of how to use Cot, see the
41//! [examples in the repository](https://github.com/cot-rs/cot/tree/master/examples).
42
43#![warn(missing_docs, rustdoc::missing_crate_level_docs)]
44#![cfg_attr(
45 docsrs,
46 feature(doc_cfg, doc_auto_cfg, rustdoc_missing_doc_code_examples)
47)]
48#![cfg_attr(docsrs, warn(rustdoc::missing_doc_code_examples))]
49
50extern crate self as cot;
51
52#[cfg(feature = "db")]
53pub mod db;
54mod error;
55pub mod form;
56mod headers;
57// Not public API. Referenced by macro-generated code.
58#[doc(hidden)]
59#[path = "private.rs"]
60pub mod __private;
61pub mod admin;
62pub mod auth;
63mod body;
64pub mod cli;
65pub mod config;
66mod error_page;
67mod handler;
68pub mod html;
69pub mod middleware;
70pub mod project;
71pub mod request;
72pub mod response;
73pub mod router;
74pub mod static_files;
75pub mod test;
76pub(crate) mod utils;
77
78pub use body::Body;
79pub use cot_macros::{main, test};
80pub use error::Error;
81pub use {bytes, http};
82
83pub use crate::handler::{BoxedHandler, RequestHandler};
84pub use crate::project::{
85 run, run_at, run_cli, App, AppBuilder, Bootstrapper, Project, ProjectContext,
86};
87
88/// A type alias for a result that can return a [`cot::Error`].
89pub type Result<T> = std::result::Result<T, Error>;
90
91/// A type alias for an HTTP status code.
92pub type StatusCode = http::StatusCode;
93
94/// A type alias for an HTTP method.
95pub type Method = http::Method;