From b3c4f982ecf9ff663824c3b4c732c50ff1bf300b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 25 Mar 2022 20:31:45 +0000 Subject: [PATCH] Fix clippy lint errors --- lib/src/key/database.rs | 6 ++++++ lib/src/key/db.rs | 6 ++++++ lib/src/key/dl.rs | 6 ++++++ lib/src/key/dt.rs | 6 ++++++ lib/src/key/ev.rs | 6 ++++++ lib/src/key/fd.rs | 6 ++++++ lib/src/key/ft.rs | 6 ++++++ lib/src/key/graph.rs | 6 ++++++ lib/src/key/guide.rs | 6 ++++++ lib/src/key/index.rs | 6 ++++++ lib/src/key/ix.rs | 6 ++++++ lib/src/key/kv.rs | 12 ++++++++++++ lib/src/key/lv.rs | 6 ++++++ lib/src/key/mod.rs | 2 +- lib/src/key/namespace.rs | 6 ++++++ lib/src/key/nl.rs | 6 ++++++ lib/src/key/ns.rs | 6 ++++++ lib/src/key/nt.rs | 6 ++++++ lib/src/key/point.rs | 6 ++++++ lib/src/key/sc.rs | 6 ++++++ lib/src/key/st.rs | 6 ++++++ lib/src/key/table.rs | 6 ++++++ lib/src/key/tb.rs | 6 ++++++ lib/src/key/thing.rs | 2 +- lib/src/sql/group.rs | 3 +++ lib/src/sql/id.rs | 2 +- lib/src/sql/order.rs | 3 +++ lib/src/sql/split.rs | 3 +++ lib/src/sql/value/value.rs | 13 ++++++++++++- src/err/mod.rs | 20 ++++++++++---------- src/net/conf.rs | 24 ++++++++++++------------ src/net/key.rs | 8 ++++---- 32 files changed, 188 insertions(+), 30 deletions(-) diff --git a/lib/src/key/database.rs b/lib/src/key/database.rs index fb2daf9c..1b392c73 100644 --- a/lib/src/key/database.rs +++ b/lib/src/key/database.rs @@ -23,6 +23,12 @@ impl From> for Database { } } +impl From<&Vec> for Database { + fn from(val: &Vec) -> Self { + Database::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str) -> Database { Database::new(ns.to_string(), db.to_string()) } diff --git a/lib/src/key/db.rs b/lib/src/key/db.rs index 2cfa94bf..48a700df 100644 --- a/lib/src/key/db.rs +++ b/lib/src/key/db.rs @@ -25,6 +25,12 @@ impl From> for Db { } } +impl From<&Vec> for Db { + fn from(val: &Vec) -> Self { + Db::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str) -> Db { Db::new(ns.to_string(), db.to_string()) } diff --git a/lib/src/key/dl.rs b/lib/src/key/dl.rs index 1246bba7..c0357653 100644 --- a/lib/src/key/dl.rs +++ b/lib/src/key/dl.rs @@ -27,6 +27,12 @@ impl From> for Dl { } } +impl From<&Vec> for Dl { + fn from(val: &Vec) -> Self { + Dl::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, dl: &str) -> Dl { Dl::new(ns.to_string(), db.to_string(), dl.to_string()) } diff --git a/lib/src/key/dt.rs b/lib/src/key/dt.rs index d49f0191..214175b2 100644 --- a/lib/src/key/dt.rs +++ b/lib/src/key/dt.rs @@ -27,6 +27,12 @@ impl From> for Dt { } } +impl From<&Vec> for Dt { + fn from(val: &Vec) -> Self { + Dt::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str) -> Dt { Dt::new(ns.to_string(), db.to_string(), tb.to_string()) } diff --git a/lib/src/key/ev.rs b/lib/src/key/ev.rs index d28d3aa6..3a98b49e 100644 --- a/lib/src/key/ev.rs +++ b/lib/src/key/ev.rs @@ -29,6 +29,12 @@ impl From> for Ev { } } +impl From<&Vec> for Ev { + fn from(val: &Vec) -> Self { + Ev::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ev: &str) -> Ev { Ev::new(ns.to_string(), db.to_string(), tb.to_string(), ev.to_string()) } diff --git a/lib/src/key/fd.rs b/lib/src/key/fd.rs index 18914dc6..1eb833fc 100644 --- a/lib/src/key/fd.rs +++ b/lib/src/key/fd.rs @@ -29,6 +29,12 @@ impl From> for Fd { } } +impl From<&Vec> for Fd { + fn from(val: &Vec) -> Self { + Fd::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, fd: &str) -> Fd { Fd::new(ns.to_string(), db.to_string(), tb.to_string(), fd.to_string()) } diff --git a/lib/src/key/ft.rs b/lib/src/key/ft.rs index 740bd262..f614ca3c 100644 --- a/lib/src/key/ft.rs +++ b/lib/src/key/ft.rs @@ -29,6 +29,12 @@ impl From> for Ft { } } +impl From<&Vec> for Ft { + fn from(val: &Vec) -> Self { + Ft::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ft: &str) -> Ft { Ft::new(ns.to_string(), db.to_string(), tb.to_string(), ft.to_string()) } diff --git a/lib/src/key/graph.rs b/lib/src/key/graph.rs index e26d631f..95793bd1 100644 --- a/lib/src/key/graph.rs +++ b/lib/src/key/graph.rs @@ -32,6 +32,12 @@ impl From> for Graph { } } +impl From<&Vec> for Graph { + fn from(val: &Vec) -> Self { + Graph::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, fk: &Thing) -> Graph { Graph::new( ns.to_string(), diff --git a/lib/src/key/guide.rs b/lib/src/key/guide.rs index 1b976acc..248faf72 100644 --- a/lib/src/key/guide.rs +++ b/lib/src/key/guide.rs @@ -27,6 +27,12 @@ impl From> for Guide { } } +impl From<&Vec> for Guide { + fn from(val: &Vec) -> Self { + Guide::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Guide { Guide::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string()) } diff --git a/lib/src/key/index.rs b/lib/src/key/index.rs index 261acbe4..0dfb242f 100644 --- a/lib/src/key/index.rs +++ b/lib/src/key/index.rs @@ -29,6 +29,12 @@ impl From> for Index { } } +impl From<&Vec> for Index { + fn from(val: &Vec) -> Self { + Index::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value) -> Index { Index::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string(), fd) } diff --git a/lib/src/key/ix.rs b/lib/src/key/ix.rs index 6ebe4970..a34082cb 100644 --- a/lib/src/key/ix.rs +++ b/lib/src/key/ix.rs @@ -29,6 +29,12 @@ impl From> for Ix { } } +impl From<&Vec> for Ix { + fn from(val: &Vec) -> Self { + Ix::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Ix { Ix::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string()) } diff --git a/lib/src/key/kv.rs b/lib/src/key/kv.rs index dc58f8d0..a46243fa 100644 --- a/lib/src/key/kv.rs +++ b/lib/src/key/kv.rs @@ -19,10 +19,22 @@ impl From> for Kv { } } +impl From<&Vec> for Kv { + fn from(val: &Vec) -> Self { + Kv::decode(val).unwrap() + } +} + pub fn new() -> Kv { Kv::new() } +impl Default for Kv { + fn default() -> Self { + Self::new() + } +} + impl Kv { pub fn new() -> Kv { Kv { diff --git a/lib/src/key/lv.rs b/lib/src/key/lv.rs index a436389f..076e03b1 100644 --- a/lib/src/key/lv.rs +++ b/lib/src/key/lv.rs @@ -29,6 +29,12 @@ impl From> for Lv { } } +impl From<&Vec> for Lv { + fn from(val: &Vec) -> Self { + Lv::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, lv: &str) -> Lv { Lv::new(ns.to_string(), db.to_string(), tb.to_string(), lv.to_string()) } diff --git a/lib/src/key/mod.rs b/lib/src/key/mod.rs index cf709fe9..a1568580 100644 --- a/lib/src/key/mod.rs +++ b/lib/src/key/mod.rs @@ -22,7 +22,7 @@ /// /// Thing /*{ns}*{db}*{tb}*{id} /// -/// Graph /*{ns}*{db}*{tb}~{id}{gt}{fk} +/// Graph /*{ns}*{db}*{tb}~{id}{gt}{fk} /// /// Guide /*{ns}*{db}*{tb}¤{ix} /// Index /*{ns}*{db}*{tb}¤{ix}{fd} diff --git a/lib/src/key/namespace.rs b/lib/src/key/namespace.rs index 891a2662..9433b762 100644 --- a/lib/src/key/namespace.rs +++ b/lib/src/key/namespace.rs @@ -21,6 +21,12 @@ impl From> for Namespace { } } +impl From<&Vec> for Namespace { + fn from(val: &Vec) -> Self { + Namespace::decode(val).unwrap() + } +} + pub fn new(ns: &str) -> Namespace { Namespace::new(ns.to_string()) } diff --git a/lib/src/key/nl.rs b/lib/src/key/nl.rs index bf32d442..b9cb2861 100644 --- a/lib/src/key/nl.rs +++ b/lib/src/key/nl.rs @@ -25,6 +25,12 @@ impl From> for Nl { } } +impl From<&Vec> for Nl { + fn from(val: &Vec) -> Self { + Nl::decode(val).unwrap() + } +} + pub fn new(ns: &str, us: &str) -> Nl { Nl::new(ns.to_string(), us.to_string()) } diff --git a/lib/src/key/ns.rs b/lib/src/key/ns.rs index ab481fde..675d7f96 100644 --- a/lib/src/key/ns.rs +++ b/lib/src/key/ns.rs @@ -23,6 +23,12 @@ impl From> for Ns { } } +impl From<&Vec> for Ns { + fn from(val: &Vec) -> Self { + Ns::decode(val).unwrap() + } +} + pub fn new(ns: &str) -> Ns { Ns::new(ns.to_string()) } diff --git a/lib/src/key/nt.rs b/lib/src/key/nt.rs index cf677e2c..ccf76e5e 100644 --- a/lib/src/key/nt.rs +++ b/lib/src/key/nt.rs @@ -25,6 +25,12 @@ impl From> for Nt { } } +impl From<&Vec> for Nt { + fn from(val: &Vec) -> Self { + Nt::decode(val).unwrap() + } +} + pub fn new(ns: &str, tk: &str) -> Nt { Nt::new(ns.to_string(), tk.to_string()) } diff --git a/lib/src/key/point.rs b/lib/src/key/point.rs index c5c2012f..493065ea 100644 --- a/lib/src/key/point.rs +++ b/lib/src/key/point.rs @@ -30,6 +30,12 @@ impl From> for Point { } } +impl From<&Vec> for Point { + fn from(val: &Vec) -> Self { + Point::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value, id: &str) -> Point { Point::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string(), fd, id.to_string()) } diff --git a/lib/src/key/sc.rs b/lib/src/key/sc.rs index baa5e45d..a2d39bbf 100644 --- a/lib/src/key/sc.rs +++ b/lib/src/key/sc.rs @@ -27,6 +27,12 @@ impl From> for Sc { } } +impl From<&Vec> for Sc { + fn from(val: &Vec) -> Self { + Sc::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, sc: &str) -> Sc { Sc::new(ns.to_string(), db.to_string(), sc.to_string()) } diff --git a/lib/src/key/st.rs b/lib/src/key/st.rs index 892c5880..4a7e3ddc 100644 --- a/lib/src/key/st.rs +++ b/lib/src/key/st.rs @@ -31,6 +31,12 @@ impl From> for St { } } +impl From<&Vec> for St { + fn from(val: &Vec) -> Self { + St::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, sc: &str, tk: &str) -> St { St::new(ns.to_string(), db.to_string(), sc.to_string(), tk.to_string()) } diff --git a/lib/src/key/table.rs b/lib/src/key/table.rs index 13587d09..63d9533e 100644 --- a/lib/src/key/table.rs +++ b/lib/src/key/table.rs @@ -25,6 +25,12 @@ impl From> for Table { } } +impl From<&Vec> for Table { + fn from(val: &Vec) -> Self { + Table::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str) -> Table { Table::new(ns.to_string(), db.to_string(), tb.to_string()) } diff --git a/lib/src/key/tb.rs b/lib/src/key/tb.rs index 9671fbde..88279f35 100644 --- a/lib/src/key/tb.rs +++ b/lib/src/key/tb.rs @@ -27,6 +27,12 @@ impl From> for Tb { } } +impl From<&Vec> for Tb { + fn from(val: &Vec) -> Self { + Tb::decode(val).unwrap() + } +} + pub fn new(ns: &str, db: &str, tb: &str) -> Tb { Tb::new(ns.to_string(), db.to_string(), tb.to_string()) } diff --git a/lib/src/key/thing.rs b/lib/src/key/thing.rs index fa3d44d4..2e0c56c3 100644 --- a/lib/src/key/thing.rs +++ b/lib/src/key/thing.rs @@ -30,7 +30,7 @@ impl From> for Thing { impl From<&Vec> for Thing { fn from(val: &Vec) -> Self { - Thing::decode(&val).unwrap() + Thing::decode(val).unwrap() } } diff --git a/lib/src/sql/group.rs b/lib/src/sql/group.rs index 7b6b0c47..9fc5abb2 100644 --- a/lib/src/sql/group.rs +++ b/lib/src/sql/group.rs @@ -17,6 +17,9 @@ impl Groups { pub fn len(&self) -> usize { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl Deref for Groups { diff --git a/lib/src/sql/id.rs b/lib/src/sql/id.rs index fcb56870..9e284e5c 100644 --- a/lib/src/sql/id.rs +++ b/lib/src/sql/id.rs @@ -57,7 +57,7 @@ impl fmt::Display for Id { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Id::Number(v) => write!(f, "{}", v), - Id::String(v) => write!(f, "{}", escape(&v, &val_char, "`")), + Id::String(v) => write!(f, "{}", escape(v, &val_char, "`")), } } } diff --git a/lib/src/sql/order.rs b/lib/src/sql/order.rs index 84dbb90c..daed8ffb 100644 --- a/lib/src/sql/order.rs +++ b/lib/src/sql/order.rs @@ -18,6 +18,9 @@ impl Orders { pub fn len(&self) -> usize { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl Deref for Orders { diff --git a/lib/src/sql/split.rs b/lib/src/sql/split.rs index 72e36481..4d506e66 100644 --- a/lib/src/sql/split.rs +++ b/lib/src/sql/split.rs @@ -17,6 +17,9 @@ impl Splits { pub fn len(&self) -> usize { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } } impl Deref for Splits { diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index 0f4d4aff..f95bc0bf 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -1,3 +1,5 @@ +#![allow(clippy::derive_ord_xor_partial_ord)] + use crate::dbs::Options; use crate::dbs::Runtime; use crate::dbs::Transaction; @@ -49,6 +51,15 @@ static MATCHER: Lazy = Lazy::new(|| SkimMatcherV2::default().igno #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] pub struct Values(pub Vec); +impl Values { + pub fn len(&self) -> usize { + self.0.len() + } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } +} + impl Deref for Values { type Target = Vec; fn deref(&self) -> &Self::Target { @@ -407,8 +418,8 @@ impl From> for Value { impl From for Value { fn from(v: Id) -> Self { match v { + Id::Number(v) => v.into(), Id::String(v) => Strand::from(v).into(), - Id::Number(v) => Number::from(v).into(), } } } diff --git a/src/err/mod.rs b/src/err/mod.rs index f20d9691..338dc367 100644 --- a/src/err/mod.rs +++ b/src/err/mod.rs @@ -5,37 +5,37 @@ use serde_cbor::error::Error as CborError; use serde_json::error::Error as JsonError; use serde_pack::encode::Error as PackError; use std::io::Error as IoError; -use surrealdb::Error as DBError; +use surrealdb::Error as DbError; use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[error("The request body contains invalid data")] - RequestError, + Request, #[error("{0}")] - DBError(#[from] DBError), + Db(#[from] DbError), #[error("IO error: {0}")] - IoError(#[from] IoError), + Io(#[from] IoError), #[error("HTTP Error: {0}")] - HyperError(#[from] HyperError), + Hyper(#[from] HyperError), #[error("HTTP Error: {0}")] - HttpError(#[from] HttpError), + Http(#[from] HttpError), #[error("JSON Error: {0}")] - JsonError(#[from] JsonError), + Json(#[from] JsonError), #[error("CBOR Error: {0}")] - CborError(#[from] CborError), + Cbor(#[from] CborError), #[error("PACK Error: {0}")] - PackError(#[from] PackError), + Pack(#[from] PackError), #[error("Reqwest Error: {0}")] - ReqwestError(#[from] ReqwestError), + Reqwest(#[from] ReqwestError), } impl warp::reject::Reject for Error {} diff --git a/src/net/conf.rs b/src/net/conf.rs index 00beef78..8ff54cfc 100644 --- a/src/net/conf.rs +++ b/src/net/conf.rs @@ -1,4 +1,5 @@ use std::net::SocketAddr; +use surrealdb::Auth; use surrealdb::Session; use warp::Filter; @@ -29,18 +30,17 @@ fn process( ns: Option, db: Option, ) -> Session { - // Specify default conf - let mut conf = Session::default(); - // Specify client ip - conf.ip = ip.map(|v| v.to_string()); - // Specify session origin - conf.or = or; - // Specify session id - conf.id = id; - // Specify namespace - conf.ns = ns; - // Specify database - conf.db = db; + // Create session + let conf = Session { + au: Auth::No, + ip: ip.map(|v| v.to_string()), + or, + id, + ns, + db, + sc: None, + sd: None, + }; // Parse authentication match au { Some(auth) if auth.starts_with("Basic") => basic(auth, conf), diff --git a/src/net/key.rs b/src/net/key.rs index 81f76d17..2762361d 100644 --- a/src/net/key.rs +++ b/src/net/key.rs @@ -151,7 +151,7 @@ async fn create_all( Err(err) => Err(warp::reject::custom(Error::from(err))), } } - Err(_) => Err(warp::reject::custom(Error::RequestError)), + Err(_) => Err(warp::reject::custom(Error::Request)), } } @@ -230,7 +230,7 @@ async fn create_one( Err(err) => Err(warp::reject::custom(Error::from(err))), } } - Err(_) => Err(warp::reject::custom(Error::RequestError)), + Err(_) => Err(warp::reject::custom(Error::Request)), } } @@ -261,7 +261,7 @@ async fn update_one( Err(err) => Err(warp::reject::custom(Error::from(err))), } } - Err(_) => Err(warp::reject::custom(Error::RequestError)), + Err(_) => Err(warp::reject::custom(Error::Request)), } } @@ -292,7 +292,7 @@ async fn modify_one( Err(err) => Err(warp::reject::custom(Error::from(err))), } } - Err(_) => Err(warp::reject::custom(Error::RequestError)), + Err(_) => Err(warp::reject::custom(Error::Request)), } }