Skip to content

Commit f12fd47

Browse files
authored
Merge pull request #13 from j2inn/granular-features
Enable a more granular feature selection
2 parents 214d0af + 2affea0 commit f12fd47

File tree

13 files changed

+45
-45
lines changed

13 files changed

+45
-45
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libhaystack"
3-
version = "1.0.9"
3+
version = "1.0.10"
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"
@@ -36,11 +36,14 @@ c-api-zinc = ["zinc"]
3636
c-api-json = ["json"]
3737

3838
# Lib features
39-
filter = ["defs", "zinc-decoding"]
40-
defs = []
41-
units = []
42-
timezone = []
43-
encoders = ["json", "zinc"]
39+
value = ["units", "timezone", "encoders"]
40+
filter = ["value", "defs", "zinc-decoding"]
41+
defs = ["value"]
42+
units = ["units-db"]
43+
units-db = []
44+
timezone = ["timezone-db"]
45+
timezone-db = []
46+
encoders = ["value", "json", "zinc"]
4447
json = ["json-encoding", "json-decoding"]
4548
json-encoding = []
4649
json-decoding = []

src/haystack/defs/namespace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! Haystack Def namespace
44
55
use dashmap::{mapref::one::Ref as MapReadRef, DashMap};
6+
use lazy_static::lazy_static;
67
use std::collections::{BTreeMap, HashSet};
78

89
use super::misc::parse_multi_line_string_to_dicts;

src/haystack/filter/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::nodes::*;
77
use super::path::Path;
88
use crate::haystack::encoding::zinc::decode::scanner::Scanner;
99
use crate::val::{Symbol, Value};
10+
use lazy_static::lazy_static;
1011

1112
use std::io::{Error, Read};
1213

src/haystack/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub mod defs;
1515
pub mod encoding;
1616
#[cfg(feature = "filter")]
1717
pub mod filter;
18+
#[cfg(feature = "timezone")]
1819
pub mod timezone;
20+
#[cfg(feature = "units")]
1921
pub mod units;
22+
#[cfg(feature = "value")]
2023
pub mod val;

src/haystack/timezone/iana.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use chrono_tz::{OffsetName, Tz, UTC};
1010
use crate::timezone::fixed_timezone;
1111

1212
/// DateTime type that supports timezones
13-
pub(crate) type DateTimeType = StdDateTime<Tz>;
13+
pub type DateTimeType = StdDateTime<Tz>;
1414

15-
pub(crate) fn make_date_time(date: StdDateTime<FixedOffset>) -> Result<DateTimeType, String> {
15+
pub fn make_date_time(date: StdDateTime<FixedOffset>) -> Result<DateTimeType, String> {
1616
use chrono::LocalResult;
1717
if let Ok(tz) = find_timezone(&fixed_timezone(&date.offset().to_string())) {
1818
Ok(match tz.from_local_datetime(&date.naive_local()) {
@@ -37,15 +37,15 @@ pub fn make_date_time_with_tz(
3737
}
3838
}
3939

40-
pub(crate) fn utc_now() -> DateTimeType {
40+
pub fn utc_now() -> DateTimeType {
4141
Utc::now().with_timezone(&UTC)
4242
}
4343

44-
pub(crate) fn is_utc(date: &DateTimeType) -> bool {
44+
pub fn is_utc(date: &DateTimeType) -> bool {
4545
date.timezone() == UTC
4646
}
4747

48-
pub(crate) fn timezone_short_name(date: &DateTimeType) -> String {
48+
pub fn timezone_short_name(date: &DateTimeType) -> String {
4949
let tz_id = date.offset().tz_id();
5050

5151
tz_id[tz_id.find('/').map_or(0, |v| v + 1)..].to_string()

src/haystack/timezone/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
//! provided by [chrono_tz](https://crates.io/crates/chrono-tz), or by just using a fixed offset datetime
77
//! by toggling the `timezone` feature.
88
9-
#[cfg(feature = "timezone")]
9+
#[cfg(feature = "timezone-db")]
1010
pub mod iana;
11-
#[cfg(feature = "timezone")]
12-
pub(crate) use iana::*;
13-
#[cfg(not(feature = "timezone"))]
11+
#[cfg(feature = "timezone-db")]
12+
pub use iana::*;
13+
#[cfg(not(feature = "timezone-db"))]
1414
pub mod utc;
15-
#[cfg(not(feature = "timezone"))]
16-
pub(crate) use utc::*;
15+
#[cfg(not(feature = "timezone-db"))]
16+
pub use utc::*;
1717

1818
pub(super) fn fixed_timezone(offset: &str) -> String {
1919
let gmt_offset = offset[2..offset.find(':').unwrap_or(3)].to_string();

src/haystack/timezone/utc.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,32 @@ use crate::timezone::fixed_timezone;
66
use chrono::{DateTime as StdDateTime, FixedOffset, TimeZone, Utc};
77

88
/// DateTime type that works with a fixed offset
9-
pub(crate) type DateTimeType = StdDateTime<FixedOffset>;
9+
pub type DateTimeType = StdDateTime<FixedOffset>;
1010

11-
pub(crate) fn make_date_time(value: DateTimeType) -> Result<DateTimeType, String> {
11+
pub fn make_date_time(value: DateTimeType) -> Result<DateTimeType, String> {
1212
Ok(value)
1313
}
1414

1515
/// Constructs an UTC datetime as the timezones are not available
1616
/// in this configuration.
17-
pub(crate) fn make_date_time_with_tz(
18-
datetime: &DateTimeType,
19-
_tz: &str,
20-
) -> Result<DateTimeType, String> {
17+
pub fn make_date_time_with_tz(datetime: &DateTimeType, _tz: &str) -> Result<DateTimeType, String> {
2118
use chrono::Offset;
2219
Ok(Utc
2320
.from_utc_datetime(&datetime.naive_utc())
2421
.with_timezone(&Utc.fix()))
2522
}
2623

27-
pub(crate) fn utc_now() -> DateTimeType {
24+
pub fn utc_now() -> DateTimeType {
2825
Utc::now().into()
2926
}
3027

31-
pub(crate) fn is_utc(date: &DateTimeType) -> bool {
28+
pub fn is_utc(date: &DateTimeType) -> bool {
3229
use chrono::Offset;
3330

3431
&Utc.fix() == date.offset()
3532
}
3633

37-
pub(crate) fn timezone_short_name(date: &DateTimeType) -> String {
34+
pub fn timezone_short_name(date: &DateTimeType) -> String {
3835
let tz_id = fixed_timezone(&date.offset().to_string());
3936

4037
tz_id[tz_id.find('/').map_or(0, |v| v + 1)..].to_string()

src/haystack/units/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,33 @@
44
55
pub mod unit;
66
pub mod unit_dimension;
7-
#[cfg(feature = "units")]
7+
#[cfg(feature = "units-db")]
88
pub mod units_generated;
9+
use lazy_static::lazy_static;
910

1011
pub use unit::Unit;
1112
pub use unit_dimension::UnitDimensions;
1213

1314
/// Get unit by name, if it is defined in the units database
1415
#[allow(unused_variables)]
1516
pub fn get_unit(unit: &str) -> Option<&'static Unit> {
16-
#[cfg(feature = "units")]
17+
#[cfg(feature = "units-db")]
1718
{
1819
return units_generated::UNITS.get(unit).copied();
1920
}
20-
#[cfg(not(feature = "units"))]
21+
#[cfg(not(feature = "units-db"))]
2122
return None;
2223
}
2324

2425
/// Tries to get the unit by name, if none is found, return a default unit
2526
pub fn get_unit_or_default(unit: &str) -> &'static Unit {
26-
if let Some(unit) = get_unit(unit) {
27-
unit
28-
} else {
29-
&*DEFAULT_UNIT
30-
}
27+
get_unit(unit).unwrap_or(&*DEFAULT_UNIT)
3128
}
3229

3330
/// Match units for the dimension
3431
#[allow(unused_variables)]
3532
pub fn match_units(dim: UnitDimensions, scale: f64) -> Vec<&'static Unit> {
36-
#[cfg(feature = "units")]
33+
#[cfg(feature = "units-db")]
3734
{
3835
units_generated::UNITS
3936
.iter()
@@ -46,11 +43,11 @@ pub fn match_units(dim: UnitDimensions, scale: f64) -> Vec<&'static Unit> {
4643
})
4744
.collect()
4845
}
49-
#[cfg(not(feature = "units"))]
46+
#[cfg(not(feature = "units-db"))]
5047
return Vec::default();
5148
}
5249

53-
#[cfg(feature = "units")]
50+
#[cfg(feature = "units-db")]
5451
fn approx_eq(a: f64, b: f64) -> bool {
5552
if a == b {
5653
return true;

src/haystack/units/unit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ mod test {
190190
let meters = get_unit("m").expect("Meters");
191191
let foot = get_unit("ft").expect("Foot");
192192
assert_eq!(meters.convert_to(1.0, foot).map(|f| f.round()), Ok(3.0));
193+
assert_eq!(foot.convert_to(1.0, meters), Ok(0.3048));
193194

194195
let fahrenheit = get_unit("°F").expect("Fahrenheit");
195196
let celsius = get_unit("°C").expect("Celsius");

0 commit comments

Comments
 (0)