logo
Expand description

Pencil is a microframework for Rust inspired by Flask.

Installation

This crate is called pencil and you can depend on it via cargo:

[dependencies]
pencil = "*"

Quickstart

A short introduction to Pencil.

A Minimal Application

A minimal Pencil application looks something like this:

extern crate sharp_pencil;

use sharp_pencil::Pencil;
use sharp_pencil::{Request, PencilResult, Response};
use sharp_pencil::method::Get;


fn hello(_: &mut Request) -> PencilResult {
    Ok(Response::from("Hello World!"))
}


fn main() {
    let mut app = Pencil::new("/web/hello");
    app.route("/", &[Get], "hello", hello);
    app.run("127.0.0.1:5000");
}

Re-exports

pub use types::PenHTTPError;
pub use types::PenUserError;
pub use wrappers::Request;
pub use wrappers::Response;
pub use http_errors::HTTPError;
pub use json::jsonify;
pub use config::Config;
pub use helpers::PathBound;
pub use helpers::safe_join;
pub use helpers::abort;
pub use helpers::redirect;
pub use helpers::escape;
pub use helpers::send_file;
pub use helpers::send_from_directory;

Modules

This module implements configuration related stuff.

This module implements some useful objects.

This module implements various helpers.

This module implements a number of http errors.

This module implements helpers for the JSON support in Pencil.

This module exports the http method.

This module implements the dispatcher.

This module implements simple request and response objects.

Structs

Content-Length header, defined in RFC7230

Content-Type header, defined in RFC7231

Cookie header, defined in RFC6265

The single entry point of your Handlebars templates

A map of header fields on requests and responses.

Represents a module.

The pencil type. It acts as the central application object. Once it is created it will act as a central registry for the view functions, the URL rules and much more.

Set-Cookie header, defined RFC6265

The Pencil User Error type.

Enums

The Pencil Error type.

Type Definitions

After request func type.

Before request func type.

HTTP Error handler type.

The Pencil Result type.

Teardown request func type.

User Error handler type.

View arguments type.

View function type.