Fix clippy lint errors

This commit is contained in:
Tobie Morgan Hitchcock 2022-03-25 20:31:45 +00:00
parent e92134c92d
commit b3c4f982ec
32 changed files with 188 additions and 30 deletions

View file

@ -23,6 +23,12 @@ impl From<Vec<u8>> for Database {
} }
} }
impl From<&Vec<u8>> for Database {
fn from(val: &Vec<u8>) -> Self {
Database::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str) -> Database { pub fn new(ns: &str, db: &str) -> Database {
Database::new(ns.to_string(), db.to_string()) Database::new(ns.to_string(), db.to_string())
} }

View file

@ -25,6 +25,12 @@ impl From<Vec<u8>> for Db {
} }
} }
impl From<&Vec<u8>> for Db {
fn from(val: &Vec<u8>) -> Self {
Db::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str) -> Db { pub fn new(ns: &str, db: &str) -> Db {
Db::new(ns.to_string(), db.to_string()) Db::new(ns.to_string(), db.to_string())
} }

View file

@ -27,6 +27,12 @@ impl From<Vec<u8>> for Dl {
} }
} }
impl From<&Vec<u8>> for Dl {
fn from(val: &Vec<u8>) -> Self {
Dl::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, dl: &str) -> Dl { pub fn new(ns: &str, db: &str, dl: &str) -> Dl {
Dl::new(ns.to_string(), db.to_string(), dl.to_string()) Dl::new(ns.to_string(), db.to_string(), dl.to_string())
} }

View file

@ -27,6 +27,12 @@ impl From<Vec<u8>> for Dt {
} }
} }
impl From<&Vec<u8>> for Dt {
fn from(val: &Vec<u8>) -> Self {
Dt::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str) -> Dt { pub fn new(ns: &str, db: &str, tb: &str) -> Dt {
Dt::new(ns.to_string(), db.to_string(), tb.to_string()) Dt::new(ns.to_string(), db.to_string(), tb.to_string())
} }

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Ev {
} }
} }
impl From<&Vec<u8>> for Ev {
fn from(val: &Vec<u8>) -> Self {
Ev::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ev: &str) -> Ev { 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()) Ev::new(ns.to_string(), db.to_string(), tb.to_string(), ev.to_string())
} }

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Fd {
} }
} }
impl From<&Vec<u8>> for Fd {
fn from(val: &Vec<u8>) -> Self {
Fd::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, fd: &str) -> Fd { 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()) Fd::new(ns.to_string(), db.to_string(), tb.to_string(), fd.to_string())
} }

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Ft {
} }
} }
impl From<&Vec<u8>> for Ft {
fn from(val: &Vec<u8>) -> Self {
Ft::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ft: &str) -> Ft { 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()) Ft::new(ns.to_string(), db.to_string(), tb.to_string(), ft.to_string())
} }

View file

@ -32,6 +32,12 @@ impl From<Vec<u8>> for Graph {
} }
} }
impl From<&Vec<u8>> for Graph {
fn from(val: &Vec<u8>) -> Self {
Graph::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, fk: &Thing) -> Graph { pub fn new(ns: &str, db: &str, tb: &str, id: &Id, eg: &Dir, fk: &Thing) -> Graph {
Graph::new( Graph::new(
ns.to_string(), ns.to_string(),

View file

@ -27,6 +27,12 @@ impl From<Vec<u8>> for Guide {
} }
} }
impl From<&Vec<u8>> for Guide {
fn from(val: &Vec<u8>) -> Self {
Guide::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Guide { 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()) Guide::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string())
} }

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Index {
} }
} }
impl From<&Vec<u8>> for Index {
fn from(val: &Vec<u8>) -> Self {
Index::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value) -> Index { 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) Index::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string(), fd)
} }

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Ix {
} }
} }
impl From<&Vec<u8>> for Ix {
fn from(val: &Vec<u8>) -> Self {
Ix::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ix: &str) -> Ix { 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()) Ix::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string())
} }

View file

@ -19,10 +19,22 @@ impl From<Vec<u8>> for Kv {
} }
} }
impl From<&Vec<u8>> for Kv {
fn from(val: &Vec<u8>) -> Self {
Kv::decode(val).unwrap()
}
}
pub fn new() -> Kv { pub fn new() -> Kv {
Kv::new() Kv::new()
} }
impl Default for Kv {
fn default() -> Self {
Self::new()
}
}
impl Kv { impl Kv {
pub fn new() -> Kv { pub fn new() -> Kv {
Kv { Kv {

View file

@ -29,6 +29,12 @@ impl From<Vec<u8>> for Lv {
} }
} }
impl From<&Vec<u8>> for Lv {
fn from(val: &Vec<u8>) -> Self {
Lv::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, lv: &str) -> Lv { 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()) Lv::new(ns.to_string(), db.to_string(), tb.to_string(), lv.to_string())
} }

View file

@ -22,7 +22,7 @@
/// ///
/// Thing /*{ns}*{db}*{tb}*{id} /// Thing /*{ns}*{db}*{tb}*{id}
/// ///
/// Graph /*{ns}*{db}*{tb}~{id}{gt}{fk} /// Graph /*{ns}*{db}*{tb}~{id}{gt}{fk}
/// ///
/// Guide /*{ns}*{db}*{tb}¤{ix} /// Guide /*{ns}*{db}*{tb}¤{ix}
/// Index /*{ns}*{db}*{tb}¤{ix}{fd} /// Index /*{ns}*{db}*{tb}¤{ix}{fd}

View file

@ -21,6 +21,12 @@ impl From<Vec<u8>> for Namespace {
} }
} }
impl From<&Vec<u8>> for Namespace {
fn from(val: &Vec<u8>) -> Self {
Namespace::decode(val).unwrap()
}
}
pub fn new(ns: &str) -> Namespace { pub fn new(ns: &str) -> Namespace {
Namespace::new(ns.to_string()) Namespace::new(ns.to_string())
} }

View file

@ -25,6 +25,12 @@ impl From<Vec<u8>> for Nl {
} }
} }
impl From<&Vec<u8>> for Nl {
fn from(val: &Vec<u8>) -> Self {
Nl::decode(val).unwrap()
}
}
pub fn new(ns: &str, us: &str) -> Nl { pub fn new(ns: &str, us: &str) -> Nl {
Nl::new(ns.to_string(), us.to_string()) Nl::new(ns.to_string(), us.to_string())
} }

View file

@ -23,6 +23,12 @@ impl From<Vec<u8>> for Ns {
} }
} }
impl From<&Vec<u8>> for Ns {
fn from(val: &Vec<u8>) -> Self {
Ns::decode(val).unwrap()
}
}
pub fn new(ns: &str) -> Ns { pub fn new(ns: &str) -> Ns {
Ns::new(ns.to_string()) Ns::new(ns.to_string())
} }

View file

@ -25,6 +25,12 @@ impl From<Vec<u8>> for Nt {
} }
} }
impl From<&Vec<u8>> for Nt {
fn from(val: &Vec<u8>) -> Self {
Nt::decode(val).unwrap()
}
}
pub fn new(ns: &str, tk: &str) -> Nt { pub fn new(ns: &str, tk: &str) -> Nt {
Nt::new(ns.to_string(), tk.to_string()) Nt::new(ns.to_string(), tk.to_string())
} }

View file

@ -30,6 +30,12 @@ impl From<Vec<u8>> for Point {
} }
} }
impl From<&Vec<u8>> for Point {
fn from(val: &Vec<u8>) -> Self {
Point::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str, ix: &str, fd: Value, id: &str) -> Point { 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()) Point::new(ns.to_string(), db.to_string(), tb.to_string(), ix.to_string(), fd, id.to_string())
} }

View file

@ -27,6 +27,12 @@ impl From<Vec<u8>> for Sc {
} }
} }
impl From<&Vec<u8>> for Sc {
fn from(val: &Vec<u8>) -> Self {
Sc::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, sc: &str) -> Sc { pub fn new(ns: &str, db: &str, sc: &str) -> Sc {
Sc::new(ns.to_string(), db.to_string(), sc.to_string()) Sc::new(ns.to_string(), db.to_string(), sc.to_string())
} }

View file

@ -31,6 +31,12 @@ impl From<Vec<u8>> for St {
} }
} }
impl From<&Vec<u8>> for St {
fn from(val: &Vec<u8>) -> Self {
St::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, sc: &str, tk: &str) -> St { 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()) St::new(ns.to_string(), db.to_string(), sc.to_string(), tk.to_string())
} }

View file

@ -25,6 +25,12 @@ impl From<Vec<u8>> for Table {
} }
} }
impl From<&Vec<u8>> for Table {
fn from(val: &Vec<u8>) -> Self {
Table::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str) -> Table { pub fn new(ns: &str, db: &str, tb: &str) -> Table {
Table::new(ns.to_string(), db.to_string(), tb.to_string()) Table::new(ns.to_string(), db.to_string(), tb.to_string())
} }

View file

@ -27,6 +27,12 @@ impl From<Vec<u8>> for Tb {
} }
} }
impl From<&Vec<u8>> for Tb {
fn from(val: &Vec<u8>) -> Self {
Tb::decode(val).unwrap()
}
}
pub fn new(ns: &str, db: &str, tb: &str) -> Tb { pub fn new(ns: &str, db: &str, tb: &str) -> Tb {
Tb::new(ns.to_string(), db.to_string(), tb.to_string()) Tb::new(ns.to_string(), db.to_string(), tb.to_string())
} }

View file

@ -30,7 +30,7 @@ impl From<Vec<u8>> for Thing {
impl From<&Vec<u8>> for Thing { impl From<&Vec<u8>> for Thing {
fn from(val: &Vec<u8>) -> Self { fn from(val: &Vec<u8>) -> Self {
Thing::decode(&val).unwrap() Thing::decode(val).unwrap()
} }
} }

View file

@ -17,6 +17,9 @@ impl Groups {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
} }
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
} }
impl Deref for Groups { impl Deref for Groups {

View file

@ -57,7 +57,7 @@ impl fmt::Display for Id {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self { match self {
Id::Number(v) => write!(f, "{}", v), Id::Number(v) => write!(f, "{}", v),
Id::String(v) => write!(f, "{}", escape(&v, &val_char, "`")), Id::String(v) => write!(f, "{}", escape(v, &val_char, "`")),
} }
} }
} }

View file

@ -18,6 +18,9 @@ impl Orders {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
} }
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
} }
impl Deref for Orders { impl Deref for Orders {

View file

@ -17,6 +17,9 @@ impl Splits {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.0.len() self.0.len()
} }
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
} }
impl Deref for Splits { impl Deref for Splits {

View file

@ -1,3 +1,5 @@
#![allow(clippy::derive_ord_xor_partial_ord)]
use crate::dbs::Options; use crate::dbs::Options;
use crate::dbs::Runtime; use crate::dbs::Runtime;
use crate::dbs::Transaction; use crate::dbs::Transaction;
@ -49,6 +51,15 @@ static MATCHER: Lazy<SkimMatcherV2> = Lazy::new(|| SkimMatcherV2::default().igno
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct Values(pub Vec<Value>); pub struct Values(pub Vec<Value>);
impl Values {
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl Deref for Values { impl Deref for Values {
type Target = Vec<Value>; type Target = Vec<Value>;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
@ -407,8 +418,8 @@ impl From<Option<String>> for Value {
impl From<Id> for Value { impl From<Id> for Value {
fn from(v: Id) -> Self { fn from(v: Id) -> Self {
match v { match v {
Id::Number(v) => v.into(),
Id::String(v) => Strand::from(v).into(), Id::String(v) => Strand::from(v).into(),
Id::Number(v) => Number::from(v).into(),
} }
} }
} }

View file

@ -5,37 +5,37 @@ use serde_cbor::error::Error as CborError;
use serde_json::error::Error as JsonError; use serde_json::error::Error as JsonError;
use serde_pack::encode::Error as PackError; use serde_pack::encode::Error as PackError;
use std::io::Error as IoError; use std::io::Error as IoError;
use surrealdb::Error as DBError; use surrealdb::Error as DbError;
use thiserror::Error; use thiserror::Error;
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
#[error("The request body contains invalid data")] #[error("The request body contains invalid data")]
RequestError, Request,
#[error("{0}")] #[error("{0}")]
DBError(#[from] DBError), Db(#[from] DbError),
#[error("IO error: {0}")] #[error("IO error: {0}")]
IoError(#[from] IoError), Io(#[from] IoError),
#[error("HTTP Error: {0}")] #[error("HTTP Error: {0}")]
HyperError(#[from] HyperError), Hyper(#[from] HyperError),
#[error("HTTP Error: {0}")] #[error("HTTP Error: {0}")]
HttpError(#[from] HttpError), Http(#[from] HttpError),
#[error("JSON Error: {0}")] #[error("JSON Error: {0}")]
JsonError(#[from] JsonError), Json(#[from] JsonError),
#[error("CBOR Error: {0}")] #[error("CBOR Error: {0}")]
CborError(#[from] CborError), Cbor(#[from] CborError),
#[error("PACK Error: {0}")] #[error("PACK Error: {0}")]
PackError(#[from] PackError), Pack(#[from] PackError),
#[error("Reqwest Error: {0}")] #[error("Reqwest Error: {0}")]
ReqwestError(#[from] ReqwestError), Reqwest(#[from] ReqwestError),
} }
impl warp::reject::Reject for Error {} impl warp::reject::Reject for Error {}

View file

@ -1,4 +1,5 @@
use std::net::SocketAddr; use std::net::SocketAddr;
use surrealdb::Auth;
use surrealdb::Session; use surrealdb::Session;
use warp::Filter; use warp::Filter;
@ -29,18 +30,17 @@ fn process(
ns: Option<String>, ns: Option<String>,
db: Option<String>, db: Option<String>,
) -> Session { ) -> Session {
// Specify default conf // Create session
let mut conf = Session::default(); let conf = Session {
// Specify client ip au: Auth::No,
conf.ip = ip.map(|v| v.to_string()); ip: ip.map(|v| v.to_string()),
// Specify session origin or,
conf.or = or; id,
// Specify session id ns,
conf.id = id; db,
// Specify namespace sc: None,
conf.ns = ns; sd: None,
// Specify database };
conf.db = db;
// Parse authentication // Parse authentication
match au { match au {
Some(auth) if auth.starts_with("Basic") => basic(auth, conf), Some(auth) if auth.starts_with("Basic") => basic(auth, conf),

View file

@ -151,7 +151,7 @@ async fn create_all(
Err(err) => Err(warp::reject::custom(Error::from(err))), 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) => 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) => 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) => Err(warp::reject::custom(Error::from(err))),
} }
} }
Err(_) => Err(warp::reject::custom(Error::RequestError)), Err(_) => Err(warp::reject::custom(Error::Request)),
} }
} }