Skip to content

Commit 248e15e

Browse files
committed
2018 edition
1 parent ed1f586 commit 248e15e

File tree

10 files changed

+60
-53
lines changed

10 files changed

+60
-53
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "msql-srv"
33
version = "0.8.5"
4+
edition = "2018"
45

56
description = "Bindings for emulating a MySQL/MariaDB server"
67
readme = "README.md"

examples/psql_as_mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<W: io::Write> MysqlShim<W> for Postgres {
187187
// we can only do that by first boxing all the values (so they can be kept in a
188188
// single vec), and then collecting a *second* vec with references to those, and
189189
// *then* take a slice of that vec.
190-
let args: Vec<Box<postgres::types::ToSql>> = ps
190+
let args: Vec<Box<dyn postgres::types::ToSql>> = ps
191191
.into_iter()
192192
.map(|p| match p.coltype {
193193
ColumnType::MYSQL_TYPE_SHORT => {

src/commands.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use myc::constants::{CapabilityFlags, Command as CommandByte};
1+
use crate::myc::constants::{CapabilityFlags, Command as CommandByte};
22
use nom;
33

44
#[derive(Debug)]
@@ -9,7 +9,7 @@ pub struct ClientHandshake<'a> {
99
username: &'a [u8],
1010
}
1111

12-
pub fn client_handshake(i: &[u8]) -> nom::IResult<&[u8], ClientHandshake> {
12+
pub fn client_handshake(i: &[u8]) -> nom::IResult<&[u8], ClientHandshake<'_>> {
1313
let (i, cap) = nom::number::complete::le_u32(i)?;
1414
let (i, maxps) = nom::number::complete::le_u32(i)?;
1515
let (i, collation) = nom::bytes::complete::take(1u8)(i)?;
@@ -47,14 +47,14 @@ pub enum Command<'a> {
4747
Quit,
4848
}
4949

50-
pub fn execute(i: &[u8]) -> nom::IResult<&[u8], Command> {
50+
pub fn execute(i: &[u8]) -> nom::IResult<&[u8], Command<'_>> {
5151
let (i, stmt) = nom::number::complete::le_u32(i)?;
5252
let (i, _flags) = nom::bytes::complete::take(1u8)(i)?;
5353
let (i, _iterations) = nom::number::complete::le_u32(i)?;
5454
Ok((&[], Command::Execute { stmt, params: i }))
5555
}
5656

57-
pub fn send_long_data(i: &[u8]) -> nom::IResult<&[u8], Command> {
57+
pub fn send_long_data(i: &[u8]) -> nom::IResult<&[u8], Command<'_>> {
5858
let (i, stmt) = nom::number::complete::le_u32(i)?;
5959
let (i, param) = nom::number::complete::le_u16(i)?;
6060
Ok((
@@ -67,7 +67,7 @@ pub fn send_long_data(i: &[u8]) -> nom::IResult<&[u8], Command> {
6767
))
6868
}
6969

70-
pub fn parse(i: &[u8]) -> nom::IResult<&[u8], Command> {
70+
pub fn parse(i: &[u8]) -> nom::IResult<&[u8], Command<'_>> {
7171
use nom::bytes::complete::tag;
7272
use nom::combinator::{map, rest};
7373
use nom::sequence::preceded;
@@ -108,8 +108,8 @@ pub fn parse(i: &[u8]) -> nom::IResult<&[u8], Command> {
108108
#[cfg(test)]
109109
mod tests {
110110
use super::*;
111-
use myc::constants::{CapabilityFlags, UTF8_GENERAL_CI};
112-
use packet::PacketReader;
111+
use crate::myc::constants::{CapabilityFlags, UTF8_GENERAL_CI};
112+
use crate::packet::PacketReader;
113113
use std::io::Cursor;
114114

115115
#[test]

src/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
//! }
8181
//! ```
8282
#![deny(missing_docs)]
83+
#![deny(rust_2018_idioms)]
8384

8485
// Note to developers: you can find decent overviews of the protocol at
8586
//
@@ -91,18 +92,15 @@
9192
//
9293
// Wireshark also does a pretty good job at parsing the MySQL protocol.
9394

94-
extern crate byteorder;
95-
extern crate chrono;
9695
extern crate mysql_common as myc;
97-
extern crate nom;
9896

9997
use std::collections::HashMap;
10098
use std::io;
10199
use std::io::prelude::*;
102100
use std::iter;
103101
use std::net;
104102

105-
pub use myc::constants::{ColumnFlags, ColumnType, StatusFlags};
103+
pub use crate::myc::constants::{ColumnFlags, ColumnType, StatusFlags};
106104

107105
mod commands;
108106
mod errorcodes;
@@ -132,10 +130,10 @@ pub struct Column {
132130
pub colflags: ColumnFlags,
133131
}
134132

135-
pub use errorcodes::ErrorKind;
136-
pub use params::{ParamParser, ParamValue, Params};
137-
pub use resultset::{InitWriter, QueryResultWriter, RowWriter, StatementMetaWriter};
138-
pub use value::{ToMysqlValue, Value, ValueInner};
133+
pub use crate::errorcodes::ErrorKind;
134+
pub use crate::params::{ParamParser, ParamValue, Params};
135+
pub use crate::resultset::{InitWriter, QueryResultWriter, RowWriter, StatementMetaWriter};
136+
pub use crate::value::{ToMysqlValue, Value, ValueInner};
139137

140138
/// Implementors of this trait can be used to drive a MySQL-compatible database backend.
141139
pub trait MysqlShim<W: Write> {
@@ -149,7 +147,11 @@ pub trait MysqlShim<W: Write> {
149147
/// The provided [`StatementMetaWriter`](struct.StatementMetaWriter.html) should be used to
150148
/// notify the client of the statement id assigned to the prepared statement, as well as to
151149
/// give metadata about the types of parameters and returned columns.
152-
fn on_prepare(&mut self, query: &str, info: StatementMetaWriter<W>) -> Result<(), Self::Error>;
150+
fn on_prepare(
151+
&mut self,
152+
query: &str,
153+
info: StatementMetaWriter<'_, W>,
154+
) -> Result<(), Self::Error>;
153155

154156
/// Called when the client executes a previously prepared statement.
155157
///
@@ -159,8 +161,8 @@ pub trait MysqlShim<W: Write> {
159161
fn on_execute(
160162
&mut self,
161163
id: u32,
162-
params: ParamParser,
163-
results: QueryResultWriter<W>,
164+
params: ParamParser<'_>,
165+
results: QueryResultWriter<'_, W>,
164166
) -> Result<(), Self::Error>;
165167

166168
/// Called when the client wishes to deallocate resources associated with a previously prepared
@@ -171,10 +173,14 @@ pub trait MysqlShim<W: Write> {
171173
///
172174
/// Results should be returned using the given
173175
/// [`QueryResultWriter`](struct.QueryResultWriter.html).
174-
fn on_query(&mut self, query: &str, results: QueryResultWriter<W>) -> Result<(), Self::Error>;
176+
fn on_query(
177+
&mut self,
178+
query: &str,
179+
results: QueryResultWriter<'_, W>,
180+
) -> Result<(), Self::Error>;
175181

176182
/// Called when client switches database.
177-
fn on_init(&mut self, _: &str, _: InitWriter<W>) -> Result<(), Self::Error> {
183+
fn on_init(&mut self, _: &str, _: InitWriter<'_, W>) -> Result<(), Self::Error> {
178184
Ok(())
179185
}
180186
}
@@ -259,7 +265,7 @@ impl<B: MysqlShim<W>, R: Read, W: Write> MysqlIntermediary<B, R, W> {
259265
}
260266

261267
fn run(mut self) -> Result<(), B::Error> {
262-
use commands::Command;
268+
use crate::commands::Command;
263269

264270
let mut stmts: HashMap<u32, _> = HashMap::new();
265271
while let Some((seq, packet)) = self.reader.next()? {

src/packet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<R> PacketReader<R> {
8181
}
8282

8383
impl<R: Read> PacketReader<R> {
84-
pub fn next(&mut self) -> io::Result<Option<(u8, Packet)>> {
84+
pub fn next(&mut self) -> io::Result<Option<(u8, Packet<'_>)>> {
8585
self.start = self.bytes.len() - self.remaining;
8686

8787
loop {
@@ -193,13 +193,13 @@ impl<'a> Deref for Packet<'a> {
193193
}
194194
}
195195

196-
fn packet(i: &[u8]) -> nom::IResult<&[u8], (u8, Packet)> {
196+
fn packet(i: &[u8]) -> nom::IResult<&[u8], (u8, Packet<'_>)> {
197197
nom::combinator::map(
198198
nom::sequence::pair(
199199
nom::multi::fold_many0(
200200
fullpacket,
201201
(0, None),
202-
|(seq, pkt): (_, Option<Packet>), (nseq, p)| {
202+
|(seq, pkt): (_, Option<Packet<'_>>), (nseq, p)| {
203203
let pkt = if let Some(mut pkt) = pkt {
204204
assert_eq!(nseq, seq + 1);
205205
pkt.extend(p);

src/params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use myc;
1+
use crate::myc;
22
use std::collections::HashMap;
3-
use {StatementData, Value};
3+
use crate::{StatementData, Value};
44

55
/// A `ParamParser` decodes query parameters included in a client's `EXECUTE` command given
66
/// type information for the expected parameters.

src/resultset.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use crate::myc::constants::{ColumnFlags, StatusFlags};
2+
use crate::packet::PacketWriter;
3+
use crate::value::ToMysqlValue;
4+
use crate::writers;
5+
use crate::{Column, ErrorKind, StatementData};
16
use byteorder::WriteBytesExt;
2-
use myc::constants::{ColumnFlags, StatusFlags};
3-
use packet::PacketWriter;
47
use std::borrow::Borrow;
58
use std::collections::HashMap;
69
use std::io::{self, Write};
7-
use value::ToMysqlValue;
8-
use writers;
9-
use {Column, ErrorKind, StatementData};
1010

1111
/// Convenience type for responding to a client `USE <db>` command.
12-
pub struct InitWriter<'a, W: Write + 'a> {
12+
pub struct InitWriter<'a, W: Write> {
1313
pub(crate) writer: &'a mut PacketWriter<W>,
1414
}
1515

@@ -37,7 +37,7 @@ impl<'a, W: Write + 'a> InitWriter<'a, W> {
3737
/// [`reply`](struct.StatementMetaWriter.html#method.reply) or
3838
/// [`error`](struct.StatementMetaWriter.html#method.error).
3939
#[must_use]
40-
pub struct StatementMetaWriter<'a, W: Write + 'a> {
40+
pub struct StatementMetaWriter<'a, W: Write> {
4141
pub(crate) writer: &'a mut PacketWriter<W>,
4242
pub(crate) stmts: &'a mut HashMap<u32, StatementData>,
4343
}
@@ -100,7 +100,7 @@ enum Finalizer {
100100
/// program may panic if an I/O error occurs when sending the end-of-records marker to the client.
101101
/// To handle such errors, call `no_more_results` explicitly.
102102
#[must_use]
103-
pub struct QueryResultWriter<'a, W: Write + 'a> {
103+
pub struct QueryResultWriter<'a, W: Write> {
104104
// XXX: specialization instead?
105105
pub(crate) is_bin: bool,
106106
pub(crate) writer: &'a mut PacketWriter<W>,
@@ -195,7 +195,7 @@ impl<'a, W: Write> Drop for QueryResultWriter<'a, W> {
195195
/// if an I/O error occurs when sending the end-of-records marker to the client. To avoid this,
196196
/// call [`finish`](struct.RowWriter.html#method.finish) explicitly.
197197
#[must_use]
198-
pub struct RowWriter<'a, W: Write + 'a> {
198+
pub struct RowWriter<'a, W: Write> {
199199
result: Option<QueryResultWriter<'a, W>>,
200200
bitmap_len: usize,
201201
data: Vec<u8>,

src/value/decode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use byteorder::{LittleEndian, ReadBytesExt};
2-
use myc::constants::ColumnType;
3-
use myc::io::ReadMysqlExt;
2+
use crate::myc::constants::ColumnType;
3+
use crate::myc::io::ReadMysqlExt;
44
use std::io;
55

66
/// MySQL value as provided when executing prepared statements.
@@ -283,10 +283,10 @@ impl<'a> Into<Duration> for Value<'a> {
283283
mod tests {
284284
use super::Value;
285285
use chrono::{self, TimeZone};
286-
use myc;
287-
use myc::io::WriteMysqlExt;
286+
use crate::myc;
287+
use crate::myc::io::WriteMysqlExt;
288288
use std::time;
289-
use {Column, ColumnFlags, ColumnType};
289+
use crate::{Column, ColumnFlags, ColumnType};
290290

291291
macro_rules! rt {
292292
($name:ident, $t:ty, $v:expr, $ct:expr) => {

src/value/encode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use byteorder::{LittleEndian, WriteBytesExt};
2-
use myc;
3-
use myc::constants::{ColumnFlags, ColumnType};
4-
use myc::io::WriteMysqlExt;
2+
use crate::myc;
3+
use crate::myc::constants::{ColumnFlags, ColumnType};
4+
use crate::myc::io::WriteMysqlExt;
55
use std::io::{self, Write};
6-
use Column;
6+
use crate::Column;
77

88
/// Implementors of this trait can be sent as a single resultset value to a MySQL/MariaDB client.
99
pub trait ToMysqlValue {
@@ -659,10 +659,10 @@ impl ToMysqlValue for myc::value::Value {
659659
mod tests {
660660
use super::ToMysqlValue;
661661
use chrono::{self, TimeZone};
662-
use myc::value;
663-
use myc::value::convert::from_value;
662+
use crate::myc::value;
663+
use crate::myc::value::convert::from_value;
664664
use std::time;
665-
use {Column, ColumnFlags, ColumnType};
665+
use crate::{Column, ColumnFlags, ColumnType};
666666

667667
mod roundtrip_text {
668668
use super::*;

src/writers.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use byteorder::{LittleEndian, WriteBytesExt};
2-
use myc::constants::StatusFlags;
3-
use myc::io::WriteMysqlExt;
4-
use packet::PacketWriter;
2+
use crate::myc::constants::StatusFlags;
3+
use crate::myc::io::WriteMysqlExt;
4+
use crate::packet::PacketWriter;
55
use std::io::{self, Write};
6-
use {Column, ErrorKind};
6+
use crate::{Column, ErrorKind};
77

88
pub(crate) fn write_eof_packet<W: Write>(
99
w: &mut PacketWriter<W>,
@@ -80,7 +80,7 @@ where
8080
let mut empty = true;
8181
for c in i {
8282
let c = c.borrow();
83-
use myc::constants::UTF8_GENERAL_CI;
83+
use crate::myc::constants::UTF8_GENERAL_CI;
8484
w.write_lenenc_str(b"def")?;
8585
w.write_lenenc_str(b"")?;
8686
w.write_lenenc_str(c.table.as_bytes())?;

0 commit comments

Comments
 (0)