Remove unnecessary functions for parsing Tables
This commit is contained in:
parent
f202bd5ab4
commit
8b28a8e5f2
2 changed files with 28 additions and 21 deletions
|
@ -2,6 +2,7 @@ use crate::dbs::Runtime;
|
||||||
use crate::err::Error;
|
use crate::err::Error;
|
||||||
use crate::sql::geometry::Geometry;
|
use crate::sql::geometry::Geometry;
|
||||||
use crate::sql::number::Number;
|
use crate::sql::number::Number;
|
||||||
|
use crate::sql::table::Table;
|
||||||
use crate::sql::thing::Thing;
|
use crate::sql::thing::Thing;
|
||||||
use crate::sql::value::Value;
|
use crate::sql::value::Value;
|
||||||
|
|
||||||
|
@ -95,7 +96,9 @@ pub fn string(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn table(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
pub fn table(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
Ok(Value::Table(args.remove(0).as_strand().value.into()))
|
Ok(Value::Table(Table {
|
||||||
|
name: args.remove(0).as_strand().value,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn thing(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
pub fn thing(_: &Runtime, mut args: Vec<Value>) -> Result<Value, Error> {
|
||||||
|
|
|
@ -27,22 +27,6 @@ pub struct Table {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<String> for Table {
|
|
||||||
fn from(s: String) -> Self {
|
|
||||||
Table {
|
|
||||||
name: s,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for Table {
|
|
||||||
fn from(t: &str) -> Table {
|
|
||||||
Table {
|
|
||||||
name: String::from(t),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for Table {
|
impl fmt::Display for Table {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "{}", escape(&self.name, &val_char, "`"))
|
write!(f, "{}", escape(&self.name, &val_char, "`"))
|
||||||
|
@ -51,7 +35,12 @@ impl fmt::Display for Table {
|
||||||
|
|
||||||
pub fn table(i: &str) -> IResult<&str, Table> {
|
pub fn table(i: &str) -> IResult<&str, Table> {
|
||||||
let (i, v) = ident_raw(i)?;
|
let (i, v) = ident_raw(i)?;
|
||||||
Ok((i, Table::from(v)))
|
Ok((
|
||||||
|
i,
|
||||||
|
Table {
|
||||||
|
name: v,
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -66,7 +55,12 @@ mod tests {
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!("test", format!("{}", out));
|
assert_eq!("test", format!("{}", out));
|
||||||
assert_eq!(out, Table::from("test"));
|
assert_eq!(
|
||||||
|
out,
|
||||||
|
Table {
|
||||||
|
name: String::from("test"),
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -76,7 +70,12 @@ mod tests {
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!("test", format!("{}", out));
|
assert_eq!("test", format!("{}", out));
|
||||||
assert_eq!(out, Table::from("test"));
|
assert_eq!(
|
||||||
|
out,
|
||||||
|
Table {
|
||||||
|
name: String::from("test"),
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -86,6 +85,11 @@ mod tests {
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
let out = res.unwrap().1;
|
let out = res.unwrap().1;
|
||||||
assert_eq!("test", format!("{}", out));
|
assert_eq!("test", format!("{}", out));
|
||||||
assert_eq!(out, Table::from("test"));
|
assert_eq!(
|
||||||
|
out,
|
||||||
|
Table {
|
||||||
|
name: String::from("test"),
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue