Coverage Report

Created: 2025-08-29 06:18

/rust/registry/src/index.crates.io-6f17d22bba15001f/icu_capi-1.5.1/src/time.rs
Line
Count
Source (jump to first uncovered line)
1
// This file is part of ICU4X. For terms of use, please see the file
2
// called LICENSE at the top level of the ICU4X source tree
3
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5
0
#[diplomat::bridge]
Unexecuted instantiation: ICU4XTime_create
Unexecuted instantiation: ICU4XTime_create_midnight
Unexecuted instantiation: ICU4XTime_hour
Unexecuted instantiation: ICU4XTime_minute
Unexecuted instantiation: ICU4XTime_second
Unexecuted instantiation: ICU4XTime_nanosecond
Unexecuted instantiation: ICU4XTime_destroy
6
pub mod ffi {
7
    use alloc::boxed::Box;
8
9
    use icu_calendar::Time;
10
11
    use crate::errors::ffi::ICU4XError;
12
13
    #[diplomat::opaque]
14
    /// An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond
15
    #[diplomat::rust_link(icu::calendar::Time, Struct)]
16
    pub struct ICU4XTime(pub Time);
17
18
    impl ICU4XTime {
19
        /// Creates a new [`ICU4XTime`] given field values
20
        #[diplomat::rust_link(icu::calendar::Time::try_new, FnInStruct)]
21
        #[diplomat::rust_link(icu::calendar::Time::new, FnInStruct, hidden)]
22
        #[diplomat::attr(all(supports = constructors, supports = fallible_constructors), constructor)]
23
0
        pub fn create(
24
0
            hour: u8,
25
0
            minute: u8,
26
0
            second: u8,
27
0
            nanosecond: u32,
28
0
        ) -> Result<Box<ICU4XTime>, ICU4XError> {
29
0
            let hour = hour.try_into()?;
30
0
            let minute = minute.try_into()?;
31
0
            let second = second.try_into()?;
32
0
            let nanosecond = nanosecond.try_into()?;
33
0
            let time = Time {
34
0
                hour,
35
0
                minute,
36
0
                second,
37
0
                nanosecond,
38
0
            };
39
0
            Ok(Box::new(ICU4XTime(time)))
40
0
        }
41
42
        /// Creates a new [`ICU4XTime`] representing midnight (00:00.000).
43
        #[diplomat::rust_link(icu::calendar::Time::midnight, FnInStruct)]
44
        #[diplomat::attr(all(supports = constructors, supports = fallible_constructors, supports = named_constructors), named_constructor = "midnight")]
45
0
        pub fn create_midnight() -> Result<Box<ICU4XTime>, ICU4XError> {
46
0
            let time = Time::midnight();
47
0
            Ok(Box::new(ICU4XTime(time)))
48
0
        }
49
50
        /// Returns the hour in this time
51
        #[diplomat::rust_link(icu::calendar::Time::hour, StructField)]
52
        #[diplomat::attr(supports = accessors, getter)]
53
0
        pub fn hour(&self) -> u8 {
54
0
            self.0.hour.into()
55
0
        }
56
        /// Returns the minute in this time
57
        #[diplomat::rust_link(icu::calendar::Time::minute, StructField)]
58
        #[diplomat::attr(supports = accessors, getter)]
59
0
        pub fn minute(&self) -> u8 {
60
0
            self.0.minute.into()
61
0
        }
62
        /// Returns the second in this time
63
        #[diplomat::rust_link(icu::calendar::Time::second, StructField)]
64
        #[diplomat::attr(supports = accessors, getter)]
65
0
        pub fn second(&self) -> u8 {
66
0
            self.0.second.into()
67
0
        }
68
        /// Returns the nanosecond in this time
69
        #[diplomat::rust_link(icu::calendar::Time::nanosecond, StructField)]
70
        #[diplomat::attr(supports = accessors, getter)]
71
0
        pub fn nanosecond(&self) -> u32 {
72
0
            self.0.nanosecond.into()
73
0
        }
74
    }
75
}