Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Run clippy auto fixes #199

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ast/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> Table<'a> {
IndexDefinition::Single(column) => {
if let Some(right_cond) = join_cond(&column)? {
match result {
ConditionTree::NegativeCondition => result = right_cond.into(),
ConditionTree::NegativeCondition => result = right_cond,
left_cond => result = left_cond.or(right_cond),
}
}
Expand All @@ -117,7 +117,7 @@ impl<'a> Table<'a> {
}

match result {
ConditionTree::NegativeCondition => result = sub_result.into(),
ConditionTree::NegativeCondition => result = sub_result,
left_cond => result = left_cond.or(sub_result),
}
}
Expand Down
68 changes: 19 additions & 49 deletions src/ast/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> From<Value<'a>> for serde_json::Value {
Value::Text(cow) => cow.map(|cow| serde_json::Value::String(cow.into_owned())),
Value::Bytes(bytes) => bytes.map(|bytes| serde_json::Value::String(base64::encode(&bytes))),
Value::Enum(cow) => cow.map(|cow| serde_json::Value::String(cow.into_owned())),
Value::Boolean(b) => b.map(|b| serde_json::Value::Bool(b)),
Value::Boolean(b) => b.map(serde_json::Value::Bool),
Value::Char(c) => c.map(|c| {
let bytes = [c as u8];
let s = std::str::from_utf8(&bytes)
Expand Down Expand Up @@ -319,10 +319,7 @@ impl<'a> Value<'a> {

/// `true` if the `Value` is text.
pub fn is_text(&self) -> bool {
match self {
Value::Text(_) => true,
_ => false,
}
matches!(self, Value::Text(_))
}

/// Returns a &str if the value is text, otherwise `None`.
Expand All @@ -337,7 +334,7 @@ impl<'a> Value<'a> {
/// Returns a char if the value is a char, otherwise `None`.
pub fn as_char(&self) -> Option<char> {
match self {
Value::Char(c) => c.clone(),
Value::Char(c) => *c,
_ => None,
}
}
Expand All @@ -363,10 +360,7 @@ impl<'a> Value<'a> {

/// Returns whether this value is the `Bytes` variant.
pub fn is_bytes(&self) -> bool {
match self {
Value::Bytes(_) => true,
_ => false,
}
matches!(self, Value::Bytes(_))
}

/// Returns a bytes slice if the value is text or a byte slice, otherwise `None`.
Expand All @@ -389,26 +383,20 @@ impl<'a> Value<'a> {

/// `true` if the `Value` is an integer.
pub fn is_integer(&self) -> bool {
match self {
Value::Integer(_) => true,
_ => false,
}
matches!(self, Value::Integer(_))
}

/// Returns an i64 if the value is an integer, otherwise `None`.
pub fn as_i64(&self) -> Option<i64> {
match self {
Value::Integer(i) => i.clone(),
Value::Integer(i) => *i,
_ => None,
}
}

/// `true` if the `Value` is a real value.
pub fn is_real(&self) -> bool {
match self {
Value::Real(_) => true,
_ => false,
}
matches!(self, Value::Real(_))
}

/// Returns a f64 if the value is a real value and the underlying decimal can be converted, otherwise `None`.
Expand All @@ -422,7 +410,7 @@ impl<'a> Value<'a> {
/// Returns a decimal if the value is a real value, otherwise `None`.
pub fn as_decimal(&self) -> Option<Decimal> {
match self {
Value::Real(d) => d.clone(),
Value::Real(d) => *d,
_ => None,
}
}
Expand All @@ -440,7 +428,7 @@ impl<'a> Value<'a> {
/// Returns a bool if the value is a boolean, otherwise `None`.
pub fn as_bool(&self) -> Option<bool> {
match self {
Value::Boolean(b) => b.clone(),
Value::Boolean(b) => *b,
// For schemas which don't tag booleans
Value::Integer(Some(i)) if *i == 0 || *i == 1 => Some(*i == 1),
_ => None,
Expand All @@ -450,91 +438,73 @@ impl<'a> Value<'a> {
/// `true` if the `Value` is an Array.
#[cfg(feature = "array")]
pub fn is_array(&self) -> bool {
match self {
Value::Array(_) => true,
_ => false,
}
matches!(self, Value::Array(_))
}

/// `true` if the `Value` is of UUID type.
#[cfg(feature = "uuid-0_8")]
pub fn is_uuid(&self) -> bool {
match self {
Value::Uuid(_) => true,
_ => false,
}
matches!(self, Value::Uuid(_))
}

/// Returns an UUID if the value is of UUID type, otherwise `None`.
#[cfg(feature = "uuid-0_8")]
pub fn as_uuid(&self) -> Option<Uuid> {
match self {
Value::Uuid(u) => u.clone(),
Value::Uuid(u) => *u,
_ => None,
}
}

/// `true` if the `Value` is a DateTime.
#[cfg(feature = "chrono-0_4")]
pub fn is_datetime(&self) -> bool {
match self {
Value::DateTime(_) => true,
_ => false,
}
matches!(self, Value::DateTime(_))
}

/// Returns a `DateTime` if the value is a `DateTime`, otherwise `None`.
#[cfg(feature = "chrono-0_4")]
pub fn as_datetime(&self) -> Option<DateTime<Utc>> {
match self {
Value::DateTime(dt) => dt.clone(),
Value::DateTime(dt) => *dt,
_ => None,
}
}

/// `true` if the `Value` is a Date.
#[cfg(feature = "chrono-0_4")]
pub fn is_date(&self) -> bool {
match self {
Value::Date(_) => true,
_ => false,
}
matches!(self, Value::Date(_))
}

/// Returns a `NaiveDate` if the value is a `Date`, otherwise `None`.
#[cfg(feature = "chrono-0_4")]
pub fn as_date(&self) -> Option<NaiveDate> {
match self {
Value::Date(dt) => dt.clone(),
Value::Date(dt) => *dt,
_ => None,
}
}

/// `true` if the `Value` is a `Time`.
#[cfg(feature = "chrono-0_4")]
pub fn is_time(&self) -> bool {
match self {
Value::Time(_) => true,
_ => false,
}
matches!(self, Value::Time(_))
}

/// Returns a `NaiveTime` if the value is a `Time`, otherwise `None`.
#[cfg(feature = "chrono-0_4")]
pub fn as_time(&self) -> Option<NaiveTime> {
match self {
Value::Time(time) => time.clone(),
Value::Time(time) => *time,
_ => None,
}
}

/// `true` if the `Value` is a JSON value.
#[cfg(feature = "json-1")]
pub fn is_json(&self) -> bool {
match self {
Value::Json(_) => true,
_ => false,
}
matches!(self, Value::Json(_))
}

/// Returns a reference to a JSON Value if of Json type, otherwise `None`.
Expand Down
2 changes: 1 addition & 1 deletion src/connector/connection_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ConnectionInfo {

return Ok(ConnectionInfo::Sqlite {
file_path: params.file_path,
db_name: params.db_name.clone(),
db_name: params.db_name,
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/connector/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ impl MssqlQueryParams {
}

fn host(&self) -> &str {
self.host.as_ref().map(|s| s.as_str()).unwrap_or("localhost")
self.host.as_deref().unwrap_or("localhost")
}

fn user(&self) -> Option<&str> {
self.user.as_ref().map(|s| s.as_str())
self.user.as_deref()
}

fn password(&self) -> Option<&str> {
self.password.as_ref().map(|s| s.as_str())
self.password.as_deref()
}

fn database(&self) -> &str {
Expand Down Expand Up @@ -368,7 +368,7 @@ impl MssqlUrl {

let params: crate::Result<HashMap<String, String>> = parts
.filter(|kv| kv != &"")
.map(|kv| kv.split("="))
.map(|kv| kv.split('='))
.map(|mut split| {
let key = split
.next()
Expand Down
2 changes: 1 addition & 1 deletion src/connector/mssql/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn conv_params<'a>(params: &'a [Value<'a>]) -> crate::Result<Vec<&'a dyn ToS
let mut builder = Error::builder(kind);
builder.set_original_message(msg);

Err(builder.build())?
return Err(builder.build())
} else {
converted.push(param as &dyn ToSql)
}
Expand Down
11 changes: 5 additions & 6 deletions src/connector/mssql/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl From<tiberius::error::Error> for Error {
.split(' ')
.last()
.unwrap()
.split("'")
.split('\'')
.nth(1)
.unwrap();

Expand All @@ -70,13 +70,12 @@ impl From<tiberius::error::Error> for Error {
tiberius::error::Error::Server(e) if e.code() == 547 => {
let index = e
.message()
.split('.')
.nth(0)
.split('.').next()
.unwrap()
.split_whitespace()
.last()
.unwrap()
.split("\"")
.split('\"')
.nth(1)
.unwrap();

Expand All @@ -95,7 +94,7 @@ impl From<tiberius::error::Error> for Error {
let index = splitted.nth(1).unwrap().to_string();

let mut builder = Error::builder(ErrorKind::UniqueConstraintViolation {
constraint: DatabaseConstraint::Index(index.to_string()),
constraint: DatabaseConstraint::Index(index),
});

builder.set_original_code(format!("{}", e.code()));
Expand All @@ -116,7 +115,7 @@ impl From<tiberius::error::Error> for Error {
let column_name = e.message().split('\'').nth(3).unwrap().to_string();

let mut builder = Error::builder(ErrorKind::LengthMismatch {
column: Some(column_name.to_owned()),
column: Some(column_name),
});

builder.set_original_code(format!("{}", e.code()));
Expand Down
14 changes: 7 additions & 7 deletions src/connector/mysql/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn conv_params<'a>(params: &[Value<'a>]) -> crate::Result<my::Params> {

for pv in params {
let res = match pv {
Value::Integer(i) => i.map(|i| my::Value::Int(i)),
Value::Integer(i) => i.map(my::Value::Int),
Value::Real(f) => match f {
Some(f) => {
let floating = f.to_string().parse::<f64>().map_err(|_| {
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn conv_params<'a>(params: &[Value<'a>]) -> crate::Result<my::Params> {
let mut builder = Error::builder(kind);
builder.set_original_message(msg);

Err(builder.build())?
return Err(builder.build())
}
#[cfg(feature = "uuid-0_8")]
Value::Uuid(u) => u.map(|u| my::Value::Bytes(u.to_hyphenated().to_string().into_bytes())),
Expand Down Expand Up @@ -212,7 +212,7 @@ impl TakeRow for my::Row {
// JSON is returned as bytes.
#[cfg(feature = "json-1")]
my::Value::Bytes(b) if column.is_json() => {
serde_json::from_slice(&b).map(|val| Value::json(val)).map_err(|_| {
serde_json::from_slice(&b).map(Value::json).map_err(|_| {
let msg = "Unable to convert bytes to JSON";
let kind = ErrorKind::conversion(msg);

Expand Down Expand Up @@ -262,7 +262,7 @@ impl TakeRow for my::Row {
column.name_str()
);
let kind = ErrorKind::value_out_of_range(msg);
Err(Error::builder(kind).build())?;
return Err(Error::builder(kind).build());
}

let time = NaiveTime::from_hms_micro(hour.into(), min.into(), sec.into(), micro);
Expand All @@ -276,12 +276,12 @@ impl TakeRow for my::Row {
my::Value::Time(is_neg, days, hours, minutes, seconds, micros) => {
if is_neg {
let kind = ErrorKind::conversion("Failed to convert a negative time");
Err(Error::builder(kind).build())?
return Err(Error::builder(kind).build())
}

if days != 0 {
let kind = ErrorKind::conversion("Failed to read a MySQL `time` as duration");
Err(Error::builder(kind).build())?
return Err(Error::builder(kind).build())
}

let time = NaiveTime::from_hms_micro(hours.into(), minutes.into(), seconds.into(), micros);
Expand Down Expand Up @@ -310,7 +310,7 @@ impl TakeRow for my::Row {
);

let kind = ErrorKind::conversion(msg);
Err(Error::builder(kind).build())?
return Err(Error::builder(kind).build())
}
},
#[cfg(not(feature = "chrono-0_4"))]
Expand Down
2 changes: 1 addition & 1 deletion src/connector/mysql/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl From<my::Error> for Error {
let splitted: Vec<&str> = message.split_whitespace().collect();
let splitted: Vec<&str> = splitted.last().map(|s| s.split('\'').collect()).unwrap();

let index = splitted[1].split(".").last().unwrap().to_string();
let index = splitted[1].split('.').last().unwrap().to_string();

let mut builder = Error::builder(ErrorKind::UniqueConstraintViolation {
constraint: DatabaseConstraint::Index(index),
Expand Down
2 changes: 1 addition & 1 deletion src/connector/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl SslParams {
})
.build()
})?;
let password = self.identity_password.0.as_ref().map(|s| s.as_str()).unwrap_or("");
let password = self.identity_password.0.as_deref().unwrap_or("");
let identity = Identity::from_pkcs12(&db, &password)?;

auth.identity(identity);
Expand Down
Loading