Skip to content

Commit

Permalink
Merge pull request #15 from rracariu/update-deps-add-default
Browse files Browse the repository at this point in the history
Update dependencies and fix some issues uncover by newer lint rules
  • Loading branch information
hecsalazarf authored Jun 13, 2023
2 parents f12fd47 + 635d92b commit 1183985
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 192 deletions.
349 changes: 218 additions & 131 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libhaystack"
version = "1.0.10"
version = "1.0.11"
description = "Rust implementation of the Haystack 4 data types, defs, filter, units, and encodings"
authors = ["J2 Innovations", "Radu Racariu <[email protected]>"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion src/c_api/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::os::raw::c_char;
/// ```
#[no_mangle]
pub extern "C" fn haystack_value_init() -> Box<Value> {
Box::new(Value::default())
Box::<Value>::default()
}

/// Destructs and free a [Value](crate::val::Value)
Expand Down
1 change: 0 additions & 1 deletion src/haystack/defs/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ impl<'a> Namespace<'a> {
pub fn protos(&'a self, parent: &Dict) -> Vec<Dict> {
parent
.keys()
.into_iter()
.map(|name| self.protos_from_def(parent, name))
.fold(Vec::new(), |mut vec, cur| {
vec.extend(cur);
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/encoding/zinc/decode/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub(crate) fn parse_number_date_time<R: Read>(
let mut read_count = 0;
let mut cur = scanner.cur;
for _ in 0..4 {
if !(b'0'..=b'9').contains(&cur) || scanner.is_eof {
if !cur.is_ascii_digit() || scanner.is_eof {
break;
}
read_count += 1;
Expand Down
44 changes: 25 additions & 19 deletions src/haystack/encoding/zinc/decode/scalar/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,27 @@ pub(crate) fn parse_datetime<R: Read>(scanner: &mut Scanner<R>) -> Result<DateTi
if tz == "UTC" {
Ok(utc.into())
} else {
match fixed_offset {
Some(fixed_offset) => {
let fixed = fixed_offset
.ymd(date.year(), date.month(), date.day())
.and_hms_nano(time.hour(), time.minute(), time.second(), time.nanosecond());
match make_date_time_with_tz(&fixed, &tz) {
Ok(datetime) => Ok(datetime.into()),
Err(err) => scanner.make_generic_err(&err),
}
}
None => match make_date_time_with_tz(&utc.with_timezone(&Utc.fix()), &tz) {
Ok(datetime) => Ok(datetime.into()),
Err(err) => scanner.make_generic_err(&err),
},
}
fixed_offset
.map_or_else(
|| make_date_time_with_tz(&utc.with_timezone(&Utc.fix()), &tz),
|offset| {
offset
.with_ymd_and_hms(
date.year(),
date.month(),
date.day(),
time.hour(),
time.minute(),
time.second(),
)
.single()
.and_then(|dt| dt.with_nanosecond(time.nanosecond()))
.ok_or_else(|| String::from("Invalid date time."))
.and_then(|fixed| make_date_time_with_tz(&fixed, &tz))
},
)
.map(DateTime::from)
.or_else(|err| scanner.make_generic_err(&err))
}
}

Expand All @@ -123,7 +129,7 @@ fn parse_time_zone<R: Read>(
if scanner.cur == b'Z' {
if scanner.safe_peek() == Some(b' ')
&& if let Some(char) = scanner.safe_peek() {
(b'A'..=b'Z').contains(&char)
char.is_ascii_uppercase()
} else {
false
}
Expand Down Expand Up @@ -158,12 +164,12 @@ fn parse_time_zone<R: Read>(
let tz_name = parse_time_zone_name(scanner)?;

let fixed_offset = if gmt_sign == "+" {
FixedOffset::east(dur.num_seconds() as i32)
FixedOffset::east_opt(dur.num_seconds() as i32)
} else {
FixedOffset::west(dur.num_seconds() as i32)
FixedOffset::west_opt(dur.num_seconds() as i32)
};

Ok((tz_name, Some(fixed_offset)))
Ok((tz_name, fixed_offset))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/haystack/encoding/zinc/decode/scalar/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn parse_number<R: Read>(scanner: &mut Scanner<R>) -> Result<Number,

if !scanner.is_eof && scanner.is_any_of("eE") {
let next = scanner.peek()?;
if next == b'+' || next == b'-' || (b'0'..=b'9').contains(&next) {
if next == b'+' || next == b'-' || next.is_ascii_digit() {
exponent = Some(parse_exponent(scanner)?);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/haystack/encoding/zinc/decode/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ impl<'a, R: Read> Scanner<'a, R> {

/// True if cur is a digit char
pub fn is_digit(&self) -> bool {
(b'0'..=b'9').contains(&self.cur)
self.cur.is_ascii_digit()
}

/// True if cur is a hex digit char
pub fn is_hex_digit(&self) -> bool {
self.is_digit() || (b'a'..=b'f').contains(&self.cur) || (b'A'..=b'F').contains(&self.cur)
self.cur.is_ascii_hexdigit()
}

/// True if cur is an upper case char
pub fn is_upper(&self) -> bool {
(b'A'..=b'Z').contains(&self.cur)
self.cur.is_ascii_uppercase()
}

/// True if cur is an lower case char
pub fn is_lower(&self) -> bool {
(b'a'..=b'z').contains(&self.cur)
self.cur.is_ascii_lowercase()
}

/// True if cur is an alpha char
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::haystack::val::Value;
/// assert!(!Bool::try_from(&false_val).unwrap().value)
///```
///
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Copy, Clone, Debug)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Copy, Clone, Debug, Default)]
pub struct Bool {
pub value: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
/// assert_eq!(Coord::try_from(&coord).unwrap().lat, 45.0);
///```
///
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Default)]
pub struct Coord {
pub lat: f64,
pub long: f64,
Expand Down
12 changes: 6 additions & 6 deletions src/haystack/val/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,39 +120,39 @@ impl From<DateTime> for Value {
}

/// Converts from `DateTimeImpl<Utc>` to a `DateTime` `Value`
#[cfg(feature = "timezone")]
#[cfg(feature = "timezone-db")]
impl From<DateTimeImpl<Utc>> for Value {
fn from(from: DateTimeImpl<Utc>) -> Self {
Value::DateTime(DateTime::from(from))
}
}

/// Converts from `DateTimeImpl<Utc>` to a `DateTime` `Value`
#[cfg(not(feature = "timezone"))]
#[cfg(not(feature = "timezone-db"))]
impl From<DateTimeImpl<Utc>> for Value {
fn from(from: DateTimeImpl<Utc>) -> Self {
Value::DateTime(DateTime { value: from.into() })
}
}

/// Converts from `DateTimeImpl<Utc>` to a `DateTime`
#[cfg(not(feature = "timezone"))]
#[cfg(not(feature = "timezone-db"))]
impl From<DateTimeImpl<Utc>> for DateTime {
fn from(from: DateTimeImpl<Utc>) -> Self {
DateTime { value: from.into() }
}
}

/// Converts from `DateTimeImpl<FixedOffset>` to a `DateTime`
#[cfg(not(feature = "timezone"))]
#[cfg(not(feature = "timezone-db"))]
impl From<DateTimeImpl<FixedOffset>> for DateTime {
fn from(from: DateTimeImpl<FixedOffset>) -> Self {
DateTime { value: from }
}
}

/// Converts from `DateTimeImpl<Utc>` to a `DateTime`
#[cfg(feature = "timezone")]
#[cfg(feature = "timezone-db")]
impl From<DateTimeImpl<Utc>> for DateTime {
fn from(from: DateTimeImpl<Utc>) -> Self {
DateTime {
Expand All @@ -162,7 +162,7 @@ impl From<DateTimeImpl<Utc>> for DateTime {
}

/// Converts from `DateTimeImpl<Tz>` to a `DateTime`
#[cfg(feature = "timezone")]
#[cfg(feature = "timezone-db")]
impl From<DateTimeImpl<chrono_tz::Tz>> for DateTime {
fn from(value: DateTimeImpl<chrono_tz::Tz>) -> Self {
DateTime { value }
Expand Down
11 changes: 1 addition & 10 deletions src/haystack/val/dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub type DictType = BTreeMap<String, Value>;
/// // Get a `Str` value from the dictionary
/// assert_eq!(dict_value.get_str("name"), Some(&"Foo".into()));
///```
#[derive(Eq, PartialEq, Hash, Clone, Debug)]
#[derive(Eq, PartialEq, Hash, Clone, Debug, Default)]
pub struct Dict {
value: DictType,
}
Expand Down Expand Up @@ -124,15 +124,6 @@ impl Dict {
}
}

/// Implements the `Default` trait for `Dict`
impl Default for Dict {
fn default() -> Self {
Dict {
value: DictType::default(),
}
}
}

/// Implement FromIterator for `Dict`
///
/// Allows constructing a `Dict` from a `(String, Value)` tuple iterator
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::iter::Iterator;
use std::ops::Index;

/// Grid Column
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash, Clone, Debug)]
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash, Clone, Debug, Default)]
pub struct Column {
/// Column name
pub name: String,
Expand Down
10 changes: 2 additions & 8 deletions src/haystack/val/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use std::fmt::Display;
use super::Value;

/// List all haystack kind types as an simple enum
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum HaystackKind {
/// No value
#[default]
Null,
/// A remove tag
Remove,
Expand Down Expand Up @@ -47,13 +48,6 @@ pub enum HaystackKind {
Grid,
}

/// Default Kind variant
impl Default for HaystackKind {
fn default() -> Self {
HaystackKind::Null
}
}

impl TryFrom<u8> for HaystackKind {
type Error = String;

Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use std::{
/// let num_unit_value = Value::from(Number::make_with_unit(100.0, "sec".into()));
/// assert_eq!(Number::try_from(&num_unit_value).unwrap().unit, get_unit("sec"));
///```
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, Default)]
pub struct Number {
pub value: f64,
pub unit: Option<&'static Unit>,
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::haystack::val::Value;
/// let str:Str = "sample string".into();
/// assert_eq!(str.as_str(), "sample string");
/// ```
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Default)]
pub struct Str {
pub value: String,
}
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::haystack::val::Value;
/// // Get the symbol value from the Value
/// assert_eq!(Symbol::try_from(&sym_value).unwrap(), Symbol::from("symbol"));
/// ```
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Default)]
pub struct Symbol {
pub value: String,
}
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::str::FromStr;
/// // Get the Time value
/// assert_eq!(Time::try_from(&time).unwrap().hour(), 16);
///```
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
#[derive(Eq, PartialEq, Copy, Clone, Debug, Default)]
pub struct Time {
value: NaiveTime,
}
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::haystack::val::Value;
/// // Get the uri value from the Value
/// assert_eq!(Uri::try_from(&uri_value).unwrap(), Uri::from("/an/uri"));
/// ```
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Default)]
pub struct Uri {
pub value: String,
}
Expand Down
2 changes: 1 addition & 1 deletion src/haystack/val/xstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::haystack::val::Value;
/// // Get the XStr value from the Value
/// assert_eq!(XStr::try_from(&xstr_value).unwrap(), XStr::make("Type", r#"{"test":"100"}"#));
/// ```
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug)]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Default)]
pub struct XStr {
pub r#type: String,
pub value: String,
Expand Down

0 comments on commit 1183985

Please sign in to comment.