pub mod server;
mod context;
mod handler;
mod catcher;
pub mod http;
pub mod routing;
pub mod state;
pub mod error;
extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate mime;
#[macro_use]
extern crate log;
pub use context::Context;
pub use server::{Server};
pub use handler::Handler;
pub use routing::Router;
pub use catcher::{Catcher, CatcherImpl};
pub use cookie;
use std::ops::{Bound, RangeBounds};
#[macro_use]
extern crate bitflags;
trait StringUtils {
fn substring(&self, start: usize, len: usize) -> &str;
fn slice(&self, range: impl RangeBounds<usize>) -> &str;
}
impl StringUtils for str {
fn substring(&self, start: usize, len: usize) -> &str {
let mut char_pos = 0;
let mut byte_start = 0;
let mut it = self.chars();
loop {
if char_pos == start { break; }
if let Some(c) = it.next() {
char_pos += 1;
byte_start += c.len_utf8();
}
else { break; }
}
char_pos = 0;
let mut byte_end = byte_start;
loop {
if char_pos == len { break; }
if let Some(c) = it.next() {
char_pos += 1;
byte_end += c.len_utf8();
}
else { break; }
}
&self[byte_start..byte_end]
}
fn slice(&self, range: impl RangeBounds<usize>) -> &str {
let start = match range.start_bound() {
Bound::Included(bound) | Bound::Excluded(bound) => *bound,
Bound::Unbounded => 0,
};
let len = match range.end_bound() {
Bound::Included(bound) => *bound + 1,
Bound::Excluded(bound) => *bound,
Bound::Unbounded => self.len(),
} - start;
self.substring(start, len)
}
}
#[derive(Clone)]
enum _Protocol {
Http,
Https,
}
#[derive(Clone)]
pub struct Protocol(_Protocol);
impl Protocol {
pub fn http() -> Protocol {
Protocol(_Protocol::Http)
}
pub fn https() -> Protocol {
Protocol(_Protocol::Https)
}
pub fn name(&self) -> &str {
match self.0 {
_Protocol::Http => "http",
_Protocol::Https => "https",
}
}
}