From 9174ac6e51da18b0f34c386986aa04af7ebaf947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Morillo?= Date: Fri, 18 Oct 2024 00:57:02 +0200 Subject: [PATCH] Sync with 1.2 remote version and upgrade version --- .github/workflows/rust.yml | 8 ++++++-- Cargo.toml | 4 ++-- README.md | 6 +++--- examples/01_hello_world.rs | 2 +- examples/02_ais_read.rs | 2 +- examples/03_ais_assemble.rs | 2 +- examples/ais_full_assemble.rs | 2 +- src/boxes/stbox.rs | 4 ++-- src/boxes/tbox.rs | 8 ++++---- src/collections/datetime/date_span.rs | 6 +++--- src/collections/datetime/date_span_set.rs | 16 ++++++++-------- src/collections/datetime/tstz_span.rs | 15 ++++++++------- src/collections/datetime/tstz_span_set.rs | 16 ++++++++-------- src/lib.rs | 16 ++++++++++++---- src/temporal/number/mod.rs | 20 +++++++++++++------- src/temporal/point/mod.rs | 20 +++++++++++++------- src/temporal/tbool.rs | 6 +++--- src/temporal/ttext.rs | 11 +++++++---- 18 files changed, 96 insertions(+), 68 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b8f4e27..092c219 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -50,5 +50,9 @@ jobs: - name: Build run: cargo build --verbose - - name: Run tests - run: cargo test --verbose + - name: Run lib tests + # They need to be run in sequence because MEOS doesn't support multi-threading + run: cargo test --verbose --lib -- --test-threads 1 + + - name: Run doc tests + run: cargo test --verbose --doc diff --git a/Cargo.toml b/Cargo.toml index 7644869..e94a46a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meos" -version = "0.1.2" +version = "0.1.3" license-file = "LICENSE" authors = ["David GarcĂ­a Morillo "] repository = "https://github.com/MobilityDB/RustMEOS" @@ -13,7 +13,7 @@ edition = "2021" [dependencies] paste = "1.0.15" -meos-sys = { path = "sys", version = "0.1.0" } +meos-sys = { path = "sys", version = "0.1.3" } chrono = "0.4.38" libc = "0.2.155" bitmask-enum = "2.2.4" diff --git a/README.md b/README.md index 2399ff1..1ada27a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ You can check the examples in the `examples/` directory. ```rust use meos::{meos_initialize, TGeomPoint}; -meos_initialize("UTC"); +meos_initialize(); let trajectory: TGeomPoint = "[POINT(1 1)@2000-01-01 08:00, POINT(2 2)@2000-01-01 08:01]".parse().unwrap(); ``` @@ -27,7 +27,7 @@ let trajectory: TGeomPoint = "[POINT(1 1)@2000-01-01 08:00, POINT(2 2)@2000-01-0 ```rust use meos::{meos_initialize, TGeomPoint}; -meos_initialize("UTC"); +meos_initialize(); let tpoint1: TGeomPoint = "[Point(0 0 0)@2001-01-01, Point(1 1 1)@2001-01-03, Point(0 0 0)@2001-01-05)".parse().unwrap(); let tpoint2: TGeomPoint = "[Point(2 0 0)@2001-01-02, Point(1 1 1)@2001-01-04, Point(2 2 2)@2001-01-06)".parse().unwrap(); @@ -42,7 +42,7 @@ println!("{distance}"); // Prints 0.5 use meos::{meos_initialize, TGeomPoint}; use geos::{Geometry} -meos_initialize("UTC"); +meos_initialize(); let trajectory: TGeomPoint = "[Point(0 0 0)@2001-01-01, Point(2 2 2)@2001-01-05)".parse().unwrap(); let geom = Geometry::new_from_wkt("Point (1 1 1)").expect("Invalid geometry"); diff --git a/examples/01_hello_world.rs b/examples/01_hello_world.rs index 51ca41f..0b1fb5a 100644 --- a/examples/01_hello_world.rs +++ b/examples/01_hello_world.rs @@ -1,7 +1,7 @@ use meos::{meos_initialize, MeosEnum, TGeomPoint}; fn main() { - meos_initialize("UTC"); + meos_initialize(); // Input temporal points in WKT format let instant_wkt = "POINT(1 1)@2000-01-01"; let sequence_discrete_wkt = "{POINT(1 1)@2000-01-01, POINT(2 2)@2000-01-02}"; diff --git a/examples/02_ais_read.rs b/examples/02_ais_read.rs index b6880f6..fbe15b7 100644 --- a/examples/02_ais_read.rs +++ b/examples/02_ais_read.rs @@ -22,7 +22,7 @@ struct AISRecord { } fn main() { - meos_initialize("UTC"); + meos_initialize(); // https://github.com/MobilityDB/MobilityDB/blob/master/meos/examples/data/ais_instants.csv let file = File::open("data/ais_instants.csv").unwrap_or_else(|_| { println!("Error opening input file"); diff --git a/examples/03_ais_assemble.rs b/examples/03_ais_assemble.rs index e10dc05..6bfa66c 100644 --- a/examples/03_ais_assemble.rs +++ b/examples/03_ais_assemble.rs @@ -47,7 +47,7 @@ struct TripRecord { } fn main() { - meos_initialize("UTC"); + meos_initialize(); let start_time = Instant::now(); let mut trips: Vec = Vec::new(); diff --git a/examples/ais_full_assemble.rs b/examples/ais_full_assemble.rs index 68627bf..381d53d 100644 --- a/examples/ais_full_assemble.rs +++ b/examples/ais_full_assemble.rs @@ -50,7 +50,7 @@ struct TripRecord { } fn main() { - meos_initialize("UTC"); + meos_initialize(); let start_time = Instant::now(); let mut trips: Vec = Vec::with_capacity(MAX_SHIPS); diff --git a/src/boxes/stbox.rs b/src/boxes/stbox.rs index 1ba8b27..a2eef7a 100644 --- a/src/boxes/stbox.rs +++ b/src/boxes/stbox.rs @@ -295,7 +295,7 @@ impl cmp::PartialEq for STBox { /// # use meos::boxes::stbox::STBox; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span1: STBox = STBox::from_str("STBOX ZT(((1.0,2.0,3.0),(4.0,5.0,6.0)),[2001-01-01, 2001-01-02])").unwrap(); /// let span2: STBox = STBox::from_str("STBOX ZT(((1.0,2.0,3.0),(4.0,5.0,6.0)),[2001-01-01, 2001-01-02])").unwrap(); /// assert_eq!(span1, span2); @@ -345,7 +345,7 @@ impl std::str::FromStr for STBox { /// use meos::boxes::r#box::Box; /// use std::str::FromStr; /// # use meos::meos_initialize; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// /// let stbox: STBox = "STBOX ZT(((1.0,2.0,3.0),(4.0,5.0,6.0)),[2001-01-01, 2001-01-02])".parse().expect("Failed to parse span"); /// let temporal_span: TsTzSpan = stbox.tstzspan(); diff --git a/src/boxes/tbox.rs b/src/boxes/tbox.rs index a4263cb..d65ccfe 100644 --- a/src/boxes/tbox.rs +++ b/src/boxes/tbox.rs @@ -81,7 +81,7 @@ impl MeosBox for TBox { /// use meos::boxes::r#box::Box; /// # use meos::meos_initialize; /// use chrono::{Utc, TimeZone, TimeDelta}; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let datetime = Utc.with_ymd_and_hms(2020, 5, 15, 12, 0, 0).unwrap(); /// let tbox = TBox::from_time(datetime); /// let tstzspan = tbox.tstzspan(); @@ -635,7 +635,7 @@ impl TBox { /// use meos::boxes::r#box::Box; /// # use std::str::FromStr; /// # use meos::meos_initialize; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let tbox = TBox::from_str("TBOXFLOAT XT([0, 10),[2020-06-01, 2020-06-05])").unwrap(); /// let shifted_scaled_tbox = tbox.shift_scale_value(Some(2.0), Some(4.0)); /// @@ -675,7 +675,7 @@ impl cmp::PartialEq for TBox { /// use meos::boxes::r#box::Box; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span1: TBox = TBox::from_str("TBOXFLOAT XT([0, 10),[2020-06-01, 2020-06-05])").unwrap(); /// let span2: TBox = TBox::from_str("TBOXFLOAT XT([0, 10),[2020-06-01, 2020-06-05])").unwrap(); /// assert_eq!(span1, span2); @@ -726,7 +726,7 @@ impl std::str::FromStr for TBox { /// # use meos::collections::datetime::tstz_span::TsTzSpan; /// use std::str::FromStr; /// # use meos::meos_initialize; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// /// let tbox: TBox = "TBOXINT XT([0, 10),[2020-06-01, 2020-06-05])".parse().expect("Failed to parse span"); /// let value_span: IntSpan = tbox.intspan(); diff --git a/src/collections/datetime/date_span.rs b/src/collections/datetime/date_span.rs index 6f8f068..6b92cd2 100644 --- a/src/collections/datetime/date_span.rs +++ b/src/collections/datetime/date_span.rs @@ -219,7 +219,7 @@ impl span::Span for DateSpan { /// use std::str::FromStr; /// # use meos::collections::base::span::Span; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span1 = DateSpan::from_str("[2019-09-08, 2019-09-10]").unwrap(); /// let span2 = DateSpan::from_str("[2019-09-12, 2019-09-14]").unwrap(); /// let distance = span1.distance_to_span(&span2); @@ -255,7 +255,7 @@ impl span::Span for DateSpan { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = DateSpan::from_str("[2019-09-08, 2019-09-10]").unwrap(); /// let span_set2 = DateSpan::from_str("[2018-08-07, 2018-08-17]").unwrap(); /// let distance = span_set1.distance_to_span(&span_set2); @@ -311,7 +311,7 @@ impl std::str::FromStr for DateSpan { /// # use std::str::FromStr; /// # use meos::meos_initialize; /// use chrono::NaiveDate; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let from_ymd_opt = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap(); /// /// let span: DateSpan = "(2019-09-08, 2019-09-10)".parse().expect("Failed to parse span"); diff --git a/src/collections/datetime/date_span_set.rs b/src/collections/datetime/date_span_set.rs index 379acbf..75771af 100644 --- a/src/collections/datetime/date_span_set.rs +++ b/src/collections/datetime/date_span_set.rs @@ -69,7 +69,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-16, 2019-09-20]}").unwrap(); /// let shifted_span_set = span_set.shift(TimeDelta::days(5)); /// @@ -96,7 +96,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-13, 2019-09-15]}").unwrap(); /// let scaled_span_set = span_set.scale(TimeDelta::days(5)); /// @@ -124,7 +124,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-11, 2019-09-12]}").unwrap(); /// let shifted_scaled_span_set = span_set.shift_scale(Some(TimeDelta::days(5)), Some(TimeDelta::days(10))); /// @@ -164,7 +164,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use chrono::{TimeDelta, TimeZone, NaiveDate}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-11, 2019-09-12]}").unwrap(); /// let timestamp = NaiveDate::from_ymd_opt(2019, 9, 5).unwrap(); /// let distance = span_set.distance_to_value(×tamp); @@ -200,7 +200,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-11, 2019-09-12]}").unwrap(); /// let span_set2 = DateSpanSet::from_str("{[2018-08-07, 2018-08-17], [2018-10-17, 2018-10-20]}").unwrap(); /// let distance = span_set1.distance_to_span_set(&span_set2); @@ -231,7 +231,7 @@ impl span_set::SpanSet for DateSpanSet { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-11, 2019-09-12]}").unwrap(); /// let span = DateSpan::from_str("[2018-08-07, 2018-08-17]").unwrap(); /// let distance = span_set.distance_to_span(&span); @@ -310,7 +310,7 @@ impl BitAnd for DateSpanSet { /// # use meos::meos_initialize; /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-15, 2019-09-20]}").unwrap(); /// let span_set2 = DateSpanSet::from_str("{[2019-09-15, 2019-09-30], [2019-11-11, 2019-11-12]}").unwrap(); /// @@ -342,7 +342,7 @@ impl BitOr for DateSpanSet { /// # use meos::meos_initialize; /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = DateSpanSet::from_str("{[2019-09-08, 2019-09-10], [2019-09-15, 2019-09-20]}").unwrap(); /// let span_set2 = DateSpanSet::from_str("{[2019-09-15, 2019-09-30], [2019-11-11, 2019-11-12]}").unwrap(); /// diff --git a/src/collections/datetime/tstz_span.rs b/src/collections/datetime/tstz_span.rs index da7c132..9de580c 100644 --- a/src/collections/datetime/tstz_span.rs +++ b/src/collections/datetime/tstz_span.rs @@ -120,7 +120,7 @@ impl span::Span for TsTzSpan { /// # use meos::meos_initialize; /// use chrono::naive::NaiveDate; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// /// let from_ymd_opt = |y, m, d| NaiveDate::from_ymd_opt(y, m, d) /// .unwrap().and_hms_opt(0, 0, 0) @@ -150,7 +150,7 @@ impl span::Span for TsTzSpan { /// # use meos::meos_initialize; /// use chrono::naive::NaiveDate; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// /// let from_ymd_opt = |y, m, d| NaiveDate::from_ymd_opt(y, m, d) /// .unwrap().and_hms_opt(0, 0, 0) @@ -181,7 +181,7 @@ impl span::Span for TsTzSpan { /// use chrono::naive::NaiveDate; /// use chrono::TimeDelta; /// # use meos::meos_initialize; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let from_ymd_opt = |y, m, d| NaiveDate::from_ymd_opt(y, m, d) /// .unwrap().and_hms_opt(0, 0, 0) /// .unwrap().and_utc(); @@ -226,7 +226,7 @@ impl span::Span for TsTzSpan { /// use std::str::FromStr; /// # use meos::collections::base::span::Span; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span1 = TsTzSpan::from_str("[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00]").unwrap(); /// let span2 = TsTzSpan::from_str("[2019-09-12 00:00:00+00, 2019-09-14 00:00:00+00]").unwrap(); /// let distance = span1.distance_to_span(&span2); @@ -255,7 +255,7 @@ impl span::Span for TsTzSpan { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = TsTzSpan::from_str("[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00]").unwrap(); /// let span_set2 = TsTzSpan::from_str("[2018-08-07 00:00:00+00, 2018-08-17 00:00:00+00]").unwrap(); /// let distance = span_set1.distance_to_span(&span_set2); @@ -311,9 +311,10 @@ impl std::str::FromStr for TsTzSpan { /// # use meos::collections::datetime::tstz_span::TsTzSpan; /// # use meos::collections::base::span::Span; /// # use std::str::FromStr; - /// # use meos::meos_initialize; + /// # use meos::{meos_initialize, meos_initialize_timezone}; /// use chrono::NaiveDate; - /// # meos_initialize("UTC"); + /// # meos_initialize(); + /// # meos_initialize_timezone("UTC"); /// let from_ymd_opt = |y, m, d| NaiveDate::from_ymd_opt(y, m, d) /// .unwrap().and_hms_opt(0, 0, 0) /// .unwrap().and_utc(); diff --git a/src/collections/datetime/tstz_span_set.rs b/src/collections/datetime/tstz_span_set.rs index fdbc75c..7c4608a 100644 --- a/src/collections/datetime/tstz_span_set.rs +++ b/src/collections/datetime/tstz_span_set.rs @@ -71,7 +71,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-16 00:00:00+00, 2019-09-20 00:00:00+00]}").unwrap(); /// let shifted_span_set = span_set.shift(TimeDelta::days(5)); /// @@ -98,7 +98,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-13 00:00:00+00, 2019-09-15 00:00:00+00]}").unwrap(); /// let scaled_span_set = span_set.scale(TimeDelta::days(5)); /// @@ -126,7 +126,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; /// use chrono::TimeDelta; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-11 00:00:00+00, 2019-09-12 00:00:00+00]}").unwrap(); /// let shifted_scaled_span_set = span_set.shift_scale(Some(TimeDelta::days(5)), Some(TimeDelta::days(10))); /// @@ -170,7 +170,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-11 00:00:00+00, 2019-09-12 00:00:00+00]}").unwrap(); /// let timestamp = Utc.with_ymd_and_hms(2019, 9, 5, 0, 0, 0).unwrap(); /// let distance = span_set.distance_to_value(×tamp); @@ -200,7 +200,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-11 00:00:00+00, 2019-09-12 00:00:00+00]}").unwrap(); /// let span_set2 = TsTzSpanSet::from_str("{[2018-08-07 00:00:00+00, 2018-08-17 00:00:00+00], [2018-10-17 00:00:00+00, 2018-10-20 00:00:00+00]}").unwrap(); /// let distance = span_set1.distance_to_span_set(&span_set2); @@ -232,7 +232,7 @@ impl span_set::SpanSet for TsTzSpanSet { /// # use chrono::{TimeDelta, TimeZone, Utc}; /// # use meos::meos_initialize; /// use std::str::FromStr; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-11 00:00:00+00, 2019-09-12 00:00:00+00]}").unwrap(); /// let span = TsTzSpan::from_str("[2018-08-07 00:00:00+00, 2018-08-17 00:00:00+00]").unwrap(); /// let distance = span_set.distance_to_span(&span); @@ -311,7 +311,7 @@ impl BitAnd for TsTzSpanSet { /// # use meos::meos_initialize; /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-15 00:00:00+00, 2019-09-20 00:00:00+00]}").unwrap(); /// let span_set2 = TsTzSpanSet::from_str("{[2019-09-15 00:00:00+00, 2019-09-30 00:00:00+00], [2019-11-11 00:00:00+00, 2019-11-12 00:00:00+00]}").unwrap(); /// @@ -343,7 +343,7 @@ impl BitOr for TsTzSpanSet { /// # use meos::meos_initialize; /// # use std::str::FromStr; /// # use meos::collections::base::span_set::SpanSet; - /// # meos_initialize("UTC"); + /// # meos_initialize(); /// let span_set1 = TsTzSpanSet::from_str("{[2019-09-08 00:00:00+00, 2019-09-10 00:00:00+00], [2019-09-15 00:00:00+00, 2019-09-20 00:00:00+00]}").unwrap(); /// let span_set2 = TsTzSpanSet::from_str("{[2019-09-15 00:00:00+00, 2019-09-30 00:00:00+00], [2019-11-11 00:00:00+00, 2019-11-12 00:00:00+00]}").unwrap(); /// diff --git a/src/lib.rs b/src/lib.rs index 48dbe81..54ea5b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,16 +59,24 @@ unsafe extern "C" fn error_handler(_error_level: i32, _error_code: i32, message: /// ``` /// # use meos::meos_initialize; /// -/// meos_initialize("UTC"); +/// meos_initialize(); /// ``` -pub fn meos_initialize(tz: &str) { +pub fn meos_initialize() { START.call_once(|| unsafe { - let ptr = CString::new(tz).unwrap(); - meos_sys::meos_initialize(ptr.as_ptr(), Some(error_handler)); + meos_sys::meos_initialize(); + meos_sys::meos_initialize_error_handler(Some(error_handler)); libc::atexit(finalize); }); } +pub fn meos_initialize_timezone(tz: &str) { + unsafe { + let ptr = CString::new(tz).unwrap(); + + meos_sys::meos_initialize_timezone(ptr.as_ptr()); + } +} + fn factory(temporal: *mut meos_sys::Temporal) -> T { let temporal_type: TemporalSubtype = unsafe { (temporal.read().subtype as u32).into() }; match temporal_type { diff --git a/src/temporal/number/mod.rs b/src/temporal/number/mod.rs index ebda31f..faef084 100644 --- a/src/temporal/number/mod.rs +++ b/src/temporal/number/mod.rs @@ -4,13 +4,14 @@ pub mod tnumber; #[cfg(test)] mod tests { - use crate::meos_initialize; + use crate::{meos_initialize, meos_initialize_timezone}; use super::*; #[test] fn instant_tint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "1@2018-01-01 08:00:00+00"; let result: tint::TInt = string.parse().unwrap(); assert_eq!( @@ -21,7 +22,8 @@ mod tests { #[test] fn sequence_tint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "[1@2018-01-01 08:00:00+00]"; let result: tint::TInt = string.parse().unwrap(); assert_eq!( @@ -32,7 +34,8 @@ mod tests { #[test] fn sequence_set_tint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "{[1@2018-01-01 08:00:00+00]}"; let result: tint::TInt = string.parse().unwrap(); assert_eq!( @@ -43,7 +46,8 @@ mod tests { #[test] fn instant_tfloat() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "1@2018-01-01 08:00:00+00"; let result: tfloat::TFloat = string.parse().unwrap(); assert_eq!( @@ -54,7 +58,8 @@ mod tests { #[test] fn sequence_tfloat() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "[1@2018-01-01 08:00:00+00]"; let result: tfloat::TFloat = string.parse().unwrap(); assert_eq!( @@ -65,7 +70,8 @@ mod tests { #[test] fn sequence_set_tfloat() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "{[1@2018-01-01 08:00:00+00]}"; let result: tfloat::TFloat = string.parse().unwrap(); assert_eq!( diff --git a/src/temporal/point/mod.rs b/src/temporal/point/mod.rs index 60a869a..1246cab 100644 --- a/src/temporal/point/mod.rs +++ b/src/temporal/point/mod.rs @@ -5,13 +5,14 @@ pub mod tpoint; #[cfg(test)] #[serial_test::serial] mod tests { - use crate::meos_initialize; + use crate::{meos_initialize, meos_initialize_timezone}; use super::*; #[test] fn instant_tgeompoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "POINT(0 0)@2018-01-01 08:00:00+00"; let result: tgeompoint::TGeomPoint = string.parse().unwrap(); assert_eq!( @@ -22,7 +23,8 @@ mod tests { #[test] fn instant_tgeogpoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "POINT(0 0)@2018-01-01 08:00:00+00"; let result: tgeogpoint::TGeogPoint = string.parse().unwrap(); assert_eq!( @@ -33,7 +35,8 @@ mod tests { #[test] fn sequence_tgeompoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "[POINT(0 0)@2018-01-01 08:00:00+00]"; let result: tgeompoint::TGeomPoint = string.parse().unwrap(); assert_eq!( @@ -44,7 +47,8 @@ mod tests { #[test] fn sequence_tgeogpoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "[POINT(0 0)@2018-01-01 08:00:00+00]"; let result: tgeogpoint::TGeogPoint = string.parse().unwrap(); assert_eq!( @@ -55,7 +59,8 @@ mod tests { #[test] fn sequence_set_tgeompoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "{[POINT(0 0)@2018-01-01 08:00:00+00]}"; let result: tgeompoint::TGeomPoint = string.parse().unwrap(); assert_eq!( @@ -66,7 +71,8 @@ mod tests { #[test] fn sequence_set_tgeogpoint() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "{[POINT(0 0)@2018-01-01 08:00:00+00]}"; let result: tgeogpoint::TGeogPoint = string.parse().unwrap(); assert_eq!( diff --git a/src/temporal/tbool.rs b/src/temporal/tbool.rs index 91748d1..0a7accd 100644 --- a/src/temporal/tbool.rs +++ b/src/temporal/tbool.rs @@ -550,7 +550,7 @@ mod tests { #[test] fn instant_tbool() { - meos_initialize("UTC"); + meos_initialize(); let string = "t@2018-01-01 08:00:00+00"; let result: TBool = string.parse().unwrap(); assert_eq!( @@ -561,7 +561,7 @@ mod tests { #[test] fn sequence_tbool() { - meos_initialize("UTC"); + meos_initialize(); let string = "[t@2018-01-01 08:00:00+00]"; let result: TBool = string.parse().unwrap(); assert_eq!( @@ -572,7 +572,7 @@ mod tests { #[test] fn sequence_set_tbool() { - meos_initialize("UTC"); + meos_initialize(); let string = "{[t@2018-01-01 08:00:00+00]}"; let result: TBool = string.parse().unwrap(); assert_eq!( diff --git a/src/temporal/ttext.rs b/src/temporal/ttext.rs index 043fb90..2e33ed1 100644 --- a/src/temporal/ttext.rs +++ b/src/temporal/ttext.rs @@ -604,13 +604,14 @@ impl Temporal for TText { #[cfg(test)] mod tests { - use crate::meos_initialize; + use crate::{meos_initialize, meos_initialize_timezone}; use super::*; #[test] fn instant_ttext() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "\"text\"@2018-01-01 08:00:00+00"; let result: TText = string.parse().unwrap(); assert_eq!( @@ -621,7 +622,8 @@ mod tests { #[test] fn sequence_ttext() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "[\"text\"@2018-01-01 08:00:00+00]"; let result: TText = string.parse().unwrap(); assert_eq!( @@ -632,7 +634,8 @@ mod tests { #[test] fn sequence_set_ttext() { - meos_initialize("UTC"); + meos_initialize(); + meos_initialize_timezone("UTC"); let string = "{[\"text\"@2018-01-01 08:00:00+00]}"; let result: TText = string.parse().unwrap(); assert_eq!(