Skip to content

Commit 5f9a08a

Browse files
authored
Feature/stk 3020 upgrade haystack 4 (#21)
* Fix compiler warnings * Fix clippy issues * Fix clippy workspace errors * Update namespace unit tests + defs lib * Fix choices * Tweak via clippy * Rework relationship query * Remove invalid test * Detect filter end of fragments + add more error unit tests * PR feedback * Update depedencies * Update dashmap * Bump major version
1 parent ba2e3a2 commit 5f9a08a

File tree

25 files changed

+1419
-3265
lines changed

25 files changed

+1419
-3265
lines changed

Cargo.lock

Lines changed: 170 additions & 193 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libhaystack"
3-
version = "1.0.14"
3+
version = "2.0.0"
44
description = "Rust implementation of the Haystack 4 data types, defs, filter, units, and encodings"
55
authors = ["J2 Innovations", "Radu Racariu <radur@j2inn.com>"]
66
edition = "2021"
@@ -61,8 +61,8 @@ uuid = { version = "1.1", features = ["v4"] }
6161
chrono = "0.4"
6262
chrono-tz = "0.6"
6363
lazy_static = "1.4"
64-
dashmap = "5.4"
6564
regex = "1.10.3"
65+
dashmap = "6.1.0"
6666

6767
[dev-dependencies]
6868
criterion = "0.3"

src/c_api/datetime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::os::raw::c_char;
1717
/// - result The Value to be updated with the result DateTime.
1818
/// # Returns
1919
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
20-
/// can be called to get the error message.
20+
/// can be called to get the error message.
2121
/// # Example
2222
/// ```rust
2323
/// # use crate::libhaystack::val::Value;
@@ -79,7 +79,7 @@ pub unsafe extern "C" fn haystack_value_get_datetime_date(
7979
/// - result The Value to be updated with the result Time.
8080
/// # Returns
8181
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
82-
/// can be called to get the error message.
82+
/// can be called to get the error message.
8383
/// # Example
8484
/// ```rust
8585
/// # use crate::libhaystack::val::Value;

src/c_api/dict.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{haystack::val::Value, val::List};
1919
/// # Returns
2020
/// - number of elements
2121
/// - -1 if there was an error getting the length, in which case the [last_error_message](super::err::last_error_message)
22-
/// can be called to get the error message.
22+
/// can be called to get the error message.
2323
/// # Example
2424
/// ```rust
2525
/// # use crate::libhaystack::val::Value;
@@ -53,7 +53,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_len(val: *const Value) -> usize
5353
/// - result The Value to be updated with the result Str List.
5454
/// # Returns
5555
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
56-
/// can be called to get the error message.
56+
/// can be called to get the error message.
5757
/// # Example
5858
/// ```rust
5959
/// # use crate::libhaystack::val::Value;
@@ -113,7 +113,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_keys(
113113
/// - entry A [Value](crate::val::Value) to be inserted into the dict
114114
/// # Returns
115115
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
116-
/// can be called to get the error message.
116+
/// can be called to get the error message.
117117
/// # Example
118118
/// ```rust
119119
/// # use crate::libhaystack::val::Value;
@@ -170,7 +170,7 @@ pub unsafe extern "C" fn haystack_value_insert_dict_entry(
170170
/// - result The Value to be updated.
171171
/// # Returns
172172
/// - 1 (True) if the operation was successful, 0 (false) if no element found, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
173-
/// can be called to get the error message.
173+
/// can be called to get the error message.
174174
/// # Example
175175
/// ```rust
176176
/// # use crate::libhaystack::val::Value;
@@ -230,7 +230,7 @@ pub unsafe extern "C" fn haystack_value_get_dict_entry(
230230
/// - key The key to be removed
231231
/// # Returns
232232
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
233-
/// can be called to get the error message.
233+
/// can be called to get the error message.
234234
/// # Example
235235
/// ```rust
236236
/// # use crate::libhaystack::val::Value;

src/c_api/grid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub unsafe extern "C" fn haystack_value_get_grid_len(val: *const Value) -> usize
4343
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
4444
/// # Arguments
4545
/// - rows List](crate::val::List) [Value](crate::val::Value) of
46-
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
46+
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
4747
/// # Returns
4848
/// - The value pointer
4949
/// - None if there was an error, in which case use [last_error_message](super::err::last_error_message)
@@ -112,7 +112,7 @@ pub unsafe extern "C" fn haystack_value_make_grid_from_rows(
112112
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
113113
/// # Arguments
114114
/// - rows a [List](crate::val::List) [Value](crate::val::Value) of
115-
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
115+
/// [Dict](crate::val::Dict) [Value](crate::val::Value)s
116116
/// # Returns
117117
/// - The value pointer
118118
/// - None if there was an error, in which case use [last_error_message](super::err::last_error_message)

src/c_api/list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub unsafe extern "C" fn haystack_value_get_list_len(val: *mut Value) -> usize {
4646
/// - entry A [Value](crate::val::Value) to be inserted into the list
4747
/// # Returns
4848
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
49-
/// can be called to get the error message.
49+
/// can be called to get the error message.
5050
/// # Example
5151
/// ```rust
5252
/// # use crate::libhaystack::val::Value;
@@ -92,7 +92,7 @@ pub unsafe extern "C" fn haystack_value_push_list_entry(
9292
/// - result The Value to be updated with the result.
9393
/// # Returns
9494
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
95-
/// can be called to get the error message.
95+
/// can be called to get the error message.
9696
/// # Example
9797
/// ```rust
9898
/// # use crate::libhaystack::val::Value;
@@ -146,7 +146,7 @@ pub unsafe extern "C" fn haystack_value_get_list_entry_at(
146146
/// - element A [Value](crate::val::Value)
147147
/// # Returns
148148
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
149-
/// can be called to get the error message.
149+
/// can be called to get the error message.
150150
/// # Example
151151
/// ```rust
152152
/// # use crate::libhaystack::val::Value;
@@ -206,7 +206,7 @@ pub unsafe extern "C" fn haystack_value_set_list_entry_at(
206206
/// - index The index were to inset the value at
207207
/// # Returns
208208
/// - 1 (True) if the operation was successful, -1 otherwise in which case the [last_error_message](super::err::last_error_message)
209-
/// can be called to get the error message.
209+
/// can be called to get the error message.
210210
/// # Example
211211
/// ```rust
212212
/// # use crate::libhaystack::val::Value;

src/c_api/number.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub unsafe extern "C" fn haystack_value_get_number_value(val: *const Value) -> f
4949
/// # Returns
5050
/// - 1 if has unit, 0 otherwise
5151
/// - -1 if there was an error, in which case the [last_error_message](super::err::last_error_message)
52-
/// can be called to get the error message.
52+
/// can be called to get the error message.
5353
/// # Example
5454
/// ```rust
5555
/// # use crate::libhaystack::val::Value;

src/haystack/defs/namespace.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> Namespace<'a> {
257257
}
258258

259259
/// Returns the supertypes of a def or an empty list if it can't be found.
260-
pub fn supertypes_of(&'a self, symbol: &Symbol) -> MapReadRef<Symbol, Vec<&'a Dict>> {
260+
pub fn supertypes_of(&'a self, symbol: &Symbol) -> MapReadRef<'a, Symbol, Vec<&'a Dict>> {
261261
if let Some(super_types) = self.supertypes_of_cache.get(symbol) {
262262
super_types
263263
} else {
@@ -315,8 +315,8 @@ impl<'a> Namespace<'a> {
315315

316316
/// Returns a list of choices for def.
317317
pub fn choices_for(&self, symbol: &Symbol) -> &Vec<Dict> {
318-
if let Some(of) = self.get(symbol).and_then(|def| def.get_symbol("of")) {
319-
self.subtypes_of(of)
318+
if self.get(symbol).is_some_and(|def| self.is_choice(def)) {
319+
self.subtypes_of(symbol)
320320
} else {
321321
&EMPTY_VEC_DICT
322322
}
@@ -326,13 +326,21 @@ impl<'a> Namespace<'a> {
326326
/// all defs that are choices.
327327
fn compute_choices(&mut self) {
328328
for (sym, def) in &self.defs {
329-
if def.get_symbol("of").is_some() {
329+
// A choice extends directly from 'choice'.
330+
if self.is_choice(def) {
330331
self.choices
331332
.insert(sym.clone(), self.choices_for(sym).clone());
332333
}
333334
}
334335
}
335336

337+
fn is_choice(&self, def: &Dict) -> bool {
338+
def.get_list("is")
339+
.into_iter()
340+
.flatten()
341+
.any(|v| v == &Value::make_symbol("choice"))
342+
}
343+
336344
/// Compute a list of the features names.
337345
fn compute_feature_names(&mut self) {
338346
let mut features = HashSet::<&str>::new();
@@ -386,7 +394,7 @@ impl<'a> Namespace<'a> {
386394
}
387395

388396
/// Return the defs inheritance as a flattened array of defs.
389-
pub fn inheritance(&'a self, symbol: &Symbol) -> MapReadRef<Symbol, Vec<&'a Dict>> {
397+
pub fn inheritance(&'a self, symbol: &Symbol) -> MapReadRef<'a, Symbol, Vec<&'a Dict>> {
390398
if let Some(inheritance) = self.inheritance_of_cache.get(symbol) {
391399
inheritance
392400
} else {
@@ -410,7 +418,7 @@ impl<'a> Namespace<'a> {
410418
/// - parent The parent def.
411419
/// - association The association.
412420
///
413-
pub fn associations(&'a self, parent: &Symbol, association: &Symbol) -> Vec<&Dict> {
421+
pub fn associations(&'a self, parent: &Symbol, association: &Symbol) -> Vec<&'a Dict> {
414422
if let Some(association_def) = self.get(association) {
415423
// Make sure the association exists and is an association.
416424
if matches!(
@@ -424,7 +432,7 @@ impl<'a> Namespace<'a> {
424432

425433
// If the association isn't computed then just get the associated defs.
426434
// For instance, this will return here if the association is 'tagOn'.
427-
if !association_def.has("computed") {
435+
if !association_def.has("computedFromReciprocal") {
428436
return self
429437
.get(parent)
430438
.and_then(|def| def.get_list(&association.value))
@@ -457,7 +465,7 @@ impl<'a> Namespace<'a> {
457465
&'a self,
458466
parent: &Symbol,
459467
reciprocal_of: &Symbol,
460-
) -> Vec<&Dict> {
468+
) -> Vec<&'a Dict> {
461469
let inheritance = self.inheritance(parent);
462470

463471
let mut matches = HashSet::<&Dict>::new();
@@ -484,7 +492,7 @@ impl<'a> Namespace<'a> {
484492
/// - parent The parent def
485493
/// # Return
486494
/// The `is` association defs
487-
pub fn is(&'a self, parent: &Symbol) -> Vec<&Dict> {
495+
pub fn is(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
488496
self.associations(parent, &Symbol::from("is"))
489497
}
490498

@@ -493,7 +501,7 @@ impl<'a> Namespace<'a> {
493501
/// - parent The parent def
494502
/// # Return
495503
/// The `tagOn` association defs
496-
pub fn tag_on(&'a self, parent: &Symbol) -> Vec<&Dict> {
504+
pub fn tag_on(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
497505
self.associations(parent, &Symbol::from("tagOn"))
498506
}
499507

@@ -502,7 +510,7 @@ impl<'a> Namespace<'a> {
502510
/// - parent The parent def
503511
/// # Return
504512
/// The `tags` association defs
505-
pub fn tags(&'a self, parent: &Symbol) -> Vec<&Dict> {
513+
pub fn tags(&'a self, parent: &Symbol) -> Vec<&'a Dict> {
506514
self.associations(parent, &Symbol::from("tags"))
507515
}
508516

@@ -511,7 +519,7 @@ impl<'a> Namespace<'a> {
511519
/// - subject The subject to reflect
512520
/// # Return
513521
/// The reflected defs
514-
pub fn reflect(&'a self, subject: &Dict) -> Reflection {
522+
pub fn reflect<'b>(&'a self, subject: &'b Dict) -> Reflection<'a> {
515523
let mut defs = Vec::<&Dict>::new();
516524
let mut markers = HashSet::<&str>::new();
517525

@@ -698,11 +706,10 @@ impl<'a> Namespace<'a> {
698706
pub fn protos(&'a self, parent: &Dict) -> Vec<Dict> {
699707
parent
700708
.keys()
701-
.map(|name| self.protos_from_def(parent, name))
702-
.fold(Vec::new(), |mut vec, cur| {
703-
vec.extend(cur);
704-
vec
705-
})
709+
.flat_map(|name| self.protos_from_def(parent, name))
710+
.collect::<HashSet<_>>()
711+
.into_iter()
712+
.collect()
706713
}
707714

708715
/// Return a reflected list of children prototypes for the parent dict.

src/haystack/encoding/zinc/decode/complex/grid.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ use super::dict::parse_dict_parts;
77
use crate::haystack::val::{Column, Dict, Grid, Value};
88
use std::io::{Error, Read};
99

10-
// Zinc [Grid](crate::val::Grid) meta
11-
#[derive(PartialEq, PartialOrd, Clone, Debug)]
12-
struct GridMeta {
13-
ver: String,
14-
meta: Option<Dict>,
15-
}
16-
1710
/// Parses a Zinc [Grid](crate::val::Grid)
1811
/// # Arguments
1912
/// - a generic ParserType

src/haystack/encoding/zinc/decode/id.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Zinc identifier decoding
44
55
use super::scanner::Scanner;
6+
use std::fmt::Display;
67
use std::io::{Error, Read};
78
use std::string::ToString;
89

@@ -21,9 +22,9 @@ impl From<&str> for Id {
2122
}
2223
}
2324

24-
impl ToString for Id {
25-
fn to_string(&self) -> String {
26-
self.value.clone()
25+
impl Display for Id {
26+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
27+
write!(f, "{}", self.value.clone())
2728
}
2829
}
2930

0 commit comments

Comments
 (0)