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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
Graph::new(
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 {
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 {
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 {
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 {
Kv::new()
}
impl Default for Kv {
fn default() -> Self {
Self::new()
}
}
impl Kv {
pub fn new() -> 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 {
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}
///
/// 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}

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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
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 {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl Deref for Groups {

View file

@ -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, "`")),
}
}
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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<SkimMatcherV2> = Lazy::new(|| SkimMatcherV2::default().igno
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
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 {
type Target = Vec<Value>;
fn deref(&self) -> &Self::Target {
@ -407,8 +418,8 @@ impl From<Option<String>> for Value {
impl From<Id> 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(),
}
}
}

View file

@ -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 {}

View file

@ -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<String>,
db: Option<String>,
) -> 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),

View file

@ -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)),
}
}