DateTime

Struct DateTime 

Source
pub struct DateTime { /* private fields */ }
Expand description

Date time associated to a local time type, expressed in the proleptic gregorian calendar

Implementations§

Source§

impl DateTime

Source

pub const fn new( year: i32, month: u8, month_day: u8, hour: u8, minute: u8, second: u8, nanoseconds: u32, local_time_type: LocalTimeType, ) -> Result<Self, TzError>

Construct a date time

§Inputs
  • year: Year
  • month: Month in [1, 12]
  • month_day: Day of the month in [1, 31]
  • hour: Hours since midnight in [0, 23]
  • minute: Minutes in [0, 59]
  • second: Seconds in [0, 60], with a possible leap second
  • nanoseconds: Nanoseconds in [0, 999_999_999]
  • local_time_type: Local time type associated to a time zone
Examples found in repository?
examples/statics.rs (line 62)
62    const DATE_TIME: DateTime = unwrap!(DateTime::new(2000, 1, 1, 1, 0, 0, 1000, unwrap!(LocalTimeType::with_ut_offset(3600))));
More examples
Hide additional examples
examples/time.rs (line 88)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source

pub fn find( year: i32, month: u8, month_day: u8, hour: u8, minute: u8, second: u8, nanoseconds: u32, time_zone_ref: TimeZoneRef<'_>, ) -> Result<FoundDateTimeList, TzError>

Available on crate feature alloc only.

Find the possible date times corresponding to a date, a time and a time zone

§Inputs
  • year: Year
  • month: Month in [1, 12]
  • month_day: Day of the month in [1, 31]
  • hour: Hours since midnight in [0, 23]
  • minute: Minutes in [0, 59]
  • second: Seconds in [0, 60], with a possible leap second
  • nanoseconds: Nanoseconds in [0, 999_999_999]
  • time_zone_ref: Reference to a time zone
Examples found in repository?
examples/time.rs (line 96)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source

pub fn find_n<'a>( buf: &'a mut [Option<FoundDateTimeKind>], year: i32, month: u8, month_day: u8, hour: u8, minute: u8, second: u8, nanoseconds: u32, time_zone_ref: TimeZoneRef<'_>, ) -> Result<FoundDateTimeListRefMut<'a>, TzError>

Find the possible date times corresponding to a date, a time and a time zone.

This method doesn’t allocate, and instead takes a preallocated buffer as an input. It returns a FoundDateTimeListRefMut wrapper which has additional methods.

§Inputs
  • buf: Preallocated buffer
  • year: Year
  • month: Month in [1, 12]
  • month_day: Day of the month in [1, 31]
  • hour: Hours since midnight in [0, 23]
  • minute: Minutes in [0, 59]
  • second: Seconds in [0, 60], with a possible leap second
  • nanoseconds: Nanoseconds in [0, 999_999_999]
  • time_zone_ref: Reference to a time zone
§Usage
use tz::datetime::{DateTime, FoundDateTimeKind};
use tz::timezone::{LocalTimeType, TimeZoneRef, Transition};

let transitions = &[Transition::new(3600, 1), Transition::new(86400, 0), Transition::new(i64::MAX, 0)];
let local_time_types = &[LocalTimeType::new(0, false, Some(b"STD"))?, LocalTimeType::new(3600, true, Some(b"DST"))?];
let time_zone_ref = TimeZoneRef::new(transitions, local_time_types, &[], &None)?;

// Buffer is too small, so the results are non exhaustive
let mut small_buf = [None; 1];
assert!(!DateTime::find_n(&mut small_buf, 1970, 1, 2, 0, 30, 0, 0, time_zone_ref)?.is_exhaustive());

// Fill buffer
let mut buf = [None; 2];
let found_date_time_list = DateTime::find_n(&mut buf, 1970, 1, 2, 0, 30, 0, 0, time_zone_ref)?;
let data = found_date_time_list.data();
assert!(found_date_time_list.is_exhaustive());
assert_eq!(found_date_time_list.count(), 2);
assert!(matches!(data, [Some(FoundDateTimeKind::Normal(..)), Some(FoundDateTimeKind::Normal(..))]));

// We can reuse the buffer
let found_date_time_list = DateTime::find_n(&mut buf, 1970, 1, 1, 1, 30, 0, 0, time_zone_ref)?;
let data = found_date_time_list.data();
assert!(found_date_time_list.is_exhaustive());
assert_eq!(found_date_time_list.count(), 1);
assert!(found_date_time_list.unique().is_none()); // FoundDateTimeKind::Skipped
assert!(matches!(data, &[Some(FoundDateTimeKind::Skipped { .. })]));
Source

pub const fn from_timespec_and_local( unix_time: i64, nanoseconds: u32, local_time_type: LocalTimeType, ) -> Result<Self, TzError>

Construct a date time from a Unix time in seconds with nanoseconds and a local time type

Source

pub const fn from_timespec( unix_time: i64, nanoseconds: u32, time_zone_ref: TimeZoneRef<'_>, ) -> Result<Self, TzError>

Construct a date time from a Unix time in seconds with nanoseconds and a time zone

Examples found in repository?
examples/time.rs (line 68)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source

pub const fn from_total_nanoseconds_and_local( total_nanoseconds: i128, local_time_type: LocalTimeType, ) -> Result<Self, TzError>

Construct a date time from total nanoseconds since Unix epoch (1970-01-01T00:00:00Z) and a local time type

Source

pub const fn from_total_nanoseconds( total_nanoseconds: i128, time_zone_ref: TimeZoneRef<'_>, ) -> Result<Self, TzError>

Construct a date time from total nanoseconds since Unix epoch (1970-01-01T00:00:00Z) and a time zone

Source

pub const fn project( &self, time_zone_ref: TimeZoneRef<'_>, ) -> Result<Self, TzError>

Project the date time into another time zone.

Leap seconds are not preserved.

Examples found in repository?
examples/statics.rs (line 65)
65    const DATE_TIME_2: DateTime = unwrap!(DATE_TIME_1.project(UTC));
More examples
Hide additional examples
examples/time.rs (line 63)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source

pub const fn duration_since(&self, earlier: Self) -> Result<Duration, Duration>

Get the duration elapsed since an earlier point in time.

Returns Ok(Duration) if earlier is before self, or Err(Duration) otherwise with the duration in the opposite direction.

Source

pub fn now(time_zone_ref: TimeZoneRef<'_>) -> Result<Self, TzError>

Available on crate feature std only.

Returns the current date time associated to the specified time zone

Examples found in repository?
examples/time.rs (line 85)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source§

impl DateTime

Source

pub const fn year(&self) -> i32

Returns year

Source

pub const fn month(&self) -> u8

Returns month in [1, 12]

Source

pub const fn month_day(&self) -> u8

Returns day of the month in [1, 31]

Source

pub const fn hour(&self) -> u8

Returns hours since midnight in [0, 23]

Source

pub const fn minute(&self) -> u8

Returns minutes in [0, 59]

Source

pub const fn second(&self) -> u8

Returns seconds in [0, 60], with a possible leap second

Source

pub const fn nanoseconds(&self) -> u32

Returns nanoseconds in [0, 999_999_999]

Examples found in repository?
examples/time.rs (line 75)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}
Source

pub const fn week_day(&self) -> u8

Returns days since Sunday in [0, 6]

Source

pub const fn year_day(&self) -> u16

Returns days since January 1 in [0, 365]

Source

pub const fn total_nanoseconds(&self) -> i128

Returns total nanoseconds since Unix epoch (1970-01-01T00:00:00Z)

Source

pub const fn local_time_type(&self) -> &LocalTimeType

Returns local time type

Source

pub const fn unix_time(&self) -> i64

Returns UTC Unix time in seconds

Examples found in repository?
examples/time.rs (line 75)
1fn main() -> Result<(), tz::Error> {
2    #[cfg(feature = "std")]
3    {
4        use tz::{DateTime, LocalTimeType, TimeZone, UtcDateTime};
5
6        //
7        // TimeZone
8        //
9
10        // 2000-01-01T00:00:00Z
11        let unix_time = 946684800;
12
13        // Get UTC time zone
14        let time_zone_utc = TimeZone::utc();
15        println!("{:?}", time_zone_utc.find_local_time_type(unix_time)?);
16
17        // Get fixed time zone at GMT-1
18        let time_zone_fixed = TimeZone::fixed(-3600)?;
19        println!("{:?}", time_zone_fixed.find_local_time_type(unix_time)?.ut_offset());
20
21        // Get local time zone (UNIX only)
22        let time_zone_local = TimeZone::local()?;
23        println!("{:?}", time_zone_local.find_local_time_type(unix_time)?.ut_offset());
24
25        // Get the current local time type
26        println!("{:?}", time_zone_local.find_current_local_time_type()?);
27
28        // Get time zone from a TZ string:
29        // From an absolute file
30        let _ = TimeZone::from_posix_tz("/usr/share/zoneinfo/Pacific/Auckland");
31        // From a file relative to the system timezone directory
32        let _ = TimeZone::from_posix_tz("Pacific/Auckland");
33        // From a time zone description
34        TimeZone::from_posix_tz("HST10")?;
35        TimeZone::from_posix_tz("<-03>3")?;
36        TimeZone::from_posix_tz("NZST-12:00:00NZDT-13:00:00,M10.1.0,M3.3.0")?;
37        // Use a leading colon to force searching for a corresponding file
38        let _ = TimeZone::from_posix_tz(":UTC");
39
40        //
41        // DateTime
42        //
43
44        // Get the current UTC date time
45        println!("{:?}", UtcDateTime::now()?);
46
47        // Create a new UTC date time (2000-01-01T00:00:00.123456789Z)
48        let utc_date_time = UtcDateTime::new(2000, 1, 1, 0, 0, 0, 123_456_789)?;
49        println!("{utc_date_time}");
50        println!("{utc_date_time:?}");
51
52        // Create a new UTC date time from a Unix time with nanoseconds (2000-01-01T00:00:00.123456789Z)
53        let other_utc_date_time = UtcDateTime::from_timespec(946684800, 123_456_789)?;
54        println!("{other_utc_date_time}");
55        println!("{other_utc_date_time:?}");
56
57        // Project the UTC date time to a time zone
58        let date_time = utc_date_time.project(TimeZone::fixed(-3600)?.as_ref())?;
59        println!("{date_time}");
60        println!("{date_time:#?}");
61
62        // Project the date time to another time zone
63        let other_date_time = date_time.project(TimeZone::fixed(3600)?.as_ref())?;
64        println!("{other_date_time}");
65        println!("{other_date_time:#?}");
66
67        // Create a new date time from a Unix time with nanoseconds and a time zone (2000-01-01T00:00:00.123456789Z)
68        let another_date_time = DateTime::from_timespec(946684800, 123_456_789, TimeZone::fixed(86400)?.as_ref())?;
69        println!("{another_date_time}");
70        println!("{another_date_time:#?}");
71
72        // Get the corresponding UTC Unix times with nanoseconds
73        println!("{:?}", (utc_date_time.unix_time(), utc_date_time.nanoseconds()));
74        println!("{:?}", (other_utc_date_time.unix_time(), other_utc_date_time.nanoseconds()));
75        println!("{:?}", (date_time.unix_time(), date_time.nanoseconds()));
76        println!("{:?}", (other_date_time.unix_time(), other_date_time.nanoseconds()));
77
78        // Nanoseconds are always added towards the future
79        let neg_utc_date_time = UtcDateTime::from_timespec(-1, 123_456_789)?;
80        println!("{neg_utc_date_time}");
81        println!("{}", neg_utc_date_time.total_nanoseconds());
82
83        // Get the current date time at the local time zone (UNIX only)
84        let time_zone_local = TimeZone::local()?;
85        println!("{:#?}", DateTime::now(time_zone_local.as_ref())?);
86
87        // Create a new date time with an UTC offset (2000-01-01T01:00:00.123456789+01:00)
88        println!("{:#?}", DateTime::new(2000, 1, 1, 1, 0, 0, 123_456_789, LocalTimeType::with_ut_offset(3600)?)?);
89
90        //
91        // Find the possible date times corresponding to a date, a time and a time zone
92        //
93        let time_zone = TimeZone::from_posix_tz("CET-1CEST,M3.5.0,M10.5.0/3")?;
94
95        // Found date time is unique
96        let found_date_times = DateTime::find(2000, 1, 1, 0, 0, 0, 0, time_zone.as_ref())?;
97        println!("{found_date_times:#?}");
98        println!("{:#?}", found_date_times.unique());
99        println!("{:#?}", found_date_times.earliest());
100        println!("{:#?}", found_date_times.latest());
101
102        // Found date time was skipped by a forward transition
103        let found_date_times = DateTime::find(2000, 3, 26, 2, 30, 0, 0, time_zone.as_ref())?;
104        println!("{found_date_times:#?}");
105        println!("{:#?}", found_date_times.unique());
106        println!("{:#?}", found_date_times.earliest());
107        println!("{:#?}", found_date_times.latest());
108
109        // Found date time is ambiguous because of a backward transition
110        let found_date_times = DateTime::find(2000, 10, 29, 2, 30, 0, 0, time_zone.as_ref())?;
111        println!("{found_date_times:#?}");
112        println!("{:#?}", found_date_times.unique());
113        println!("{:#?}", found_date_times.earliest());
114        println!("{:#?}", found_date_times.latest());
115    }
116
117    Ok(())
118}

Trait Implementations§

Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for DateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DateTime> for SystemTime

Available on crate feature std only.
Source§

fn from(date_time: DateTime) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for DateTime

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for DateTime

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl TryFrom<DateTime> for UtcDateTime

Source§

type Error = TzError

The type returned in the event of a conversion error.
Source§

fn try_from(date_time: DateTime) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for DateTime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.