summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/src/metazone_calculator.rs
blob: e55ede26bd334d2d1af656fd0a5a328274b096b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#[diplomat::bridge]
pub mod ffi {
    use crate::errors::ffi::ICU4XError;
    use crate::provider::ffi::ICU4XDataProvider;
    use alloc::boxed::Box;
    use icu_timezone::MetazoneCalculator;

    /// An object capable of computing the metazone from a timezone.
    ///
    /// This can be used via `maybe_calculate_metazone()` on [`ICU4XCustomTimeZone`].
    ///
    /// [`ICU4XCustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone
    #[diplomat::opaque]
    #[diplomat::rust_link(icu::timezone::MetazoneCalculator, Struct)]
    pub struct ICU4XMetazoneCalculator(pub MetazoneCalculator);

    impl ICU4XMetazoneCalculator {
        #[diplomat::rust_link(icu::timezone::MetazoneCalculator::new, FnInStruct)]
        pub fn create(
            provider: &ICU4XDataProvider,
        ) -> Result<Box<ICU4XMetazoneCalculator>, ICU4XError> {
            Ok(Box::new(ICU4XMetazoneCalculator(call_constructor!(
                MetazoneCalculator::new [r => Ok(r)],
                MetazoneCalculator::try_new_with_any_provider,
                MetazoneCalculator::try_new_with_buffer_provider,
                provider,
            )?)))
        }
    }
}