1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2017 Anatoly Ikorsky
//
// Licensed under the Apache License, Version 2.0
// <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT
// license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. All files in the project carrying such notice may not be copied,
// modified, or distributed except according to those terms.

extern crate atoi;
extern crate bit_vec;
#[macro_use]
extern crate bitflags;
extern crate byteorder;
pub extern crate chrono;
#[macro_use]
extern crate lazy_static;
extern crate regex;
#[cfg(feature = "rustc_serialize")]
pub extern crate rustc_serialize;
pub extern crate serde;
pub extern crate serde_json;
extern crate smallvec;
pub extern crate time;
extern crate twox_hash;
pub extern crate uuid;

/// Macro to conveniently generate named parameters for a statement.
/// Parameter name is `T` where `String: From<T>`, and
///
/// ```ignore
/// params! {
///     "param_name_1" => param_value_1,
///     "param_name_2" => param_value_2,
/// }
/// ```
#[macro_export]
macro_rules! params {
    ($($name:expr => $value:expr),*) => (
        vec![
            $((::std::string::String::from($name), $crate::value::Value::from($value))),*
        ]
    );
    ($($name:expr => $value:expr),*,) => (
        params!($($name => $value),*)
    );
}

/// Non panicking Slice::split_at
macro_rules! split_at_or_err {
    ($reader:expr, $at:expr, $msg:expr) => {
        if $reader.len() >= $at {
            Ok($reader.split_at($at))
        } else {
            Err(io::Error::new(io::ErrorKind::UnexpectedEof, $msg))
        }
    };
}

/// Reads MySql's length-encoded string
#[macro_export]
macro_rules! read_lenenc_str {
    ($reader:expr) => {
        $reader.read_lenenc_int().and_then(|len| {
            let (value, rest) = split_at_or_err!($reader,
                                                 len as usize,
                                                 "EOF while reading length-encoded string")?;
            *$reader = rest;
            Ok(value)
        })
    };
}

pub mod constants;
pub mod io;
pub mod named_params;
#[macro_use]
pub mod packets;
pub mod params;
pub mod row;
pub mod value;