From 32a895de9b62618de588a050a5e49cfc7f74cc72 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Tue, 13 Oct 2026 23:53:10 +0530 Subject: [PATCH 01/15] Add time_point constructor overloads and tests --- cpp-overload-test/src/lib.rs | 1 + cpp-overload-test/src/stdcpp/time_point.rs | 147 +++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 cpp-overload-test/src/stdcpp/time_point.rs diff --git a/cpp-overload-test/src/lib.rs b/cpp-overload-test/src/lib.rs index b72552c..dc280df 100644 --- a/cpp-overload-test/src/lib.rs +++ b/cpp-overload-test/src/lib.rs @@ -8,4 +8,5 @@ pub mod stdcpp { // Add new modules for each type here, in alphabetical order. pub mod forward_list; + pub mod time_point; } diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs new file mode 100644 index 0000000..a734d24 --- /dev/null +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -0,0 +1,147 @@ +//! C++ overloads tests for [std::chrono::time_point][time_point] +//! +//! This file tests three constructors that can be represented in Rust. +//! +//! ### Limitations +//! +//! C++ time points use clock and duration types. +//! This test uses fixed types instead of supporting all possible types. +//! +//! [time_point]: https://en.cppreference.com/cpp/chrono/time_point + +#![allow(unused_braces, reason = "Generated by overload! macro")] + +use cpp::cpp; +use splat_overload::overload; +use std::ffi::{c_longlong, c_void}; +use std::marker::PhantomData; + +cpp! {{ + #include + + using TestClock = std::chrono::system_clock; + using TestDuration = std::chrono::milliseconds; + using TestTimePoint = + std::chrono::time_point; + + using TestSecondsTimePoint = + std::chrono::time_point; +}} + +/// A wrapper around a C++ time point with millisecond precision. +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +pub struct StdTimePoint(*mut c_void, PhantomData<()>); + +/// A Wrapper around a C++ time point with second precision. +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +pub struct StdSecondsTimePoint(*mut c_void, PhantomData<()>); + +impl StdSecondsTimePoint { + /// Construct a time point from seconds since the epoch. + fn from_seconds(seconds: i64) -> Self { + let point = unsafe { + cpp!([seconds as "long long"] -> *mut c_void as + "TestSecondsTimePoint*" { + return new TestSecondsTimePoint( + std::chrono::seconds(seconds) + ); + }) + }; + + Self(point, PhantomData) + } +} + +impl StdTimePoint { + /// Construct a time point at the clock's epoch. + fn default() -> Self { + let point = unsafe { + cpp!([] -> *mut c_void as "TestTimePoint*" { + return new TestTimePoint(); + }) + }; + + Self(point, PhantomData) + } + + /// Construct a time point from milliseconds since the epoch. + fn from_duration(milliseconds: i64) -> Self { + let point = unsafe { + cpp!([milliseconds as "long long"] -> *mut c_void as + "TestTimePoint*" { + return new TestTimePoint( + TestDuration(milliseconds) + ); + }) + }; + + Self(point, PhantomData) + } + + /// Construct a millisecond time point from second time point. + fn from_other(other: &StdSecondsTimePoint) -> Self { + let other = other.0 as *const c_void; + + let point = unsafe { + cpp!([other as "const TestSecondsTimePoint*"] -> *mut + c_void as "TestTimePoint*" { + return new TestTimePoint(*other); + + }) + }; + + Self(point, PhantomData) + } + + /// Return the number of milliseconds since epoch. + fn milliseconds_since_epoch(&self) -> i64 { + let point = self.0 as *const c_void; + + unsafe { + cpp!([point as "const TestTimePoint*"] -> c_longlong as + "long long" { + return point->time_since_epoch().count(); + }) + } + } +} + +// ### Ergonomics +// C++ allows constructors with the same name but different arguments. +// +// Rust does not normallly support constructor overloading. +// The overload! macro allows these constructors to share the name new. +overload! { + impl StdTimePoint { + /// Construct time point at clock's epoch. + pub fn new() -> StdTimePoint { + StdTimePoint::default() + } + + /// Construct time point from milliseconds since the epoch. + pub fn new(milliseconds: i64) -> StdTimePoint { + StdTimePoint::from_duration(milliseconds) + } + + /// Construct time point from seconds-resolution time point. + pub fn new(other: &StdSecondsTimePoint) -> StdTimePoint { + StdTimePoint::from_other(other) + } + } +} + +#[test] +fn test_time_point_constructors() { + // Test the default constructor. + let epoch = StdTimePoint::new(); + assert_eq!(epoch.milliseconds_since_epoch(), 0); + + // Test the duration constructor. + let milliseconds = StdTimePoint::new(1500_i64); + assert_eq!(milliseconds.milliseconds_since_epoch(), 1500); + + // Test the converting constructor. + let seconds = StdSecondsTimePoint::from_seconds(2); + let converted = StdTimePoint::new(&seconds); + assert_eq!(converted.milliseconds_since_epoch(), 2000); +} From 52406dde37f937f4ee8990160220b3442c84e46e Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Wed, 14 Oct 2026 17:09:44 +0530 Subject: [PATCH 02/15] Fix dead code warnings --- cpp-overload-test/src/stdcpp/time_point.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index a734d24..31c2b60 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -38,6 +38,7 @@ pub struct StdSecondsTimePoint(*mut c_void, PhantomData<()>); impl StdSecondsTimePoint { /// Construct a time point from seconds since the epoch. + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_seconds(seconds: i64) -> Self { let point = unsafe { cpp!([seconds as "long long"] -> *mut c_void as @@ -54,6 +55,7 @@ impl StdSecondsTimePoint { impl StdTimePoint { /// Construct a time point at the clock's epoch. + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn default() -> Self { let point = unsafe { cpp!([] -> *mut c_void as "TestTimePoint*" { @@ -65,6 +67,7 @@ impl StdTimePoint { } /// Construct a time point from milliseconds since the epoch. + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_duration(milliseconds: i64) -> Self { let point = unsafe { cpp!([milliseconds as "long long"] -> *mut c_void as @@ -79,6 +82,7 @@ impl StdTimePoint { } /// Construct a millisecond time point from second time point. + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_other(other: &StdSecondsTimePoint) -> Self { let other = other.0 as *const c_void; @@ -94,6 +98,7 @@ impl StdTimePoint { } /// Return the number of milliseconds since epoch. + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn milliseconds_since_epoch(&self) -> i64 { let point = self.0 as *const c_void; From 345fc9ecb602965fd070985f72cbf05642fc8256 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Wed, 14 Oct 2026 17:41:27 +0530 Subject: [PATCH 03/15] Align dead code expectations --- cpp-overload-test/src/stdcpp/time_point.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index 31c2b60..b3642bc 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -36,9 +36,9 @@ pub struct StdTimePoint(*mut c_void, PhantomData<()>); #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] pub struct StdSecondsTimePoint(*mut c_void, PhantomData<()>); +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] impl StdSecondsTimePoint { /// Construct a time point from seconds since the epoch. - #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_seconds(seconds: i64) -> Self { let point = unsafe { cpp!([seconds as "long long"] -> *mut c_void as @@ -53,9 +53,9 @@ impl StdSecondsTimePoint { } } +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] impl StdTimePoint { /// Construct a time point at the clock's epoch. - #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn default() -> Self { let point = unsafe { cpp!([] -> *mut c_void as "TestTimePoint*" { @@ -67,7 +67,6 @@ impl StdTimePoint { } /// Construct a time point from milliseconds since the epoch. - #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_duration(milliseconds: i64) -> Self { let point = unsafe { cpp!([milliseconds as "long long"] -> *mut c_void as @@ -82,7 +81,6 @@ impl StdTimePoint { } /// Construct a millisecond time point from second time point. - #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn from_other(other: &StdSecondsTimePoint) -> Self { let other = other.0 as *const c_void; @@ -98,7 +96,6 @@ impl StdTimePoint { } /// Return the number of milliseconds since epoch. - #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] fn milliseconds_since_epoch(&self) -> i64 { let point = self.0 as *const c_void; From 8822a5e106a6201ad637decf603cf332cadc62de Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Sun, 18 Oct 2026 21:46:27 +0530 Subject: [PATCH 04/15] Update time point types and overloads --- cpp-overload-test/src/stdcpp/time_point.rs | 346 ++++++++++++++++++++- 1 file changed, 330 insertions(+), 16 deletions(-) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index b3642bc..ed2ff9b 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -21,25 +21,76 @@ cpp! {{ using TestClock = std::chrono::system_clock; using TestDuration = std::chrono::milliseconds; + using TestSecondsDuration = std::chrono::seconds; + using TestTimePoint = std::chrono::time_point; using TestSecondsTimePoint = - std::chrono::time_point; + std::chrono::time_point; }} /// A wrapper around a C++ time point with millisecond precision. #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] -pub struct StdTimePoint(*mut c_void, PhantomData<()>); +pub struct StdMillisecondsTimePoint(*mut c_void, PhantomData<()>); /// A Wrapper around a C++ time point with second precision. #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] pub struct StdSecondsTimePoint(*mut c_void, PhantomData<()>); +/// A wrapper around a c++ duration with millisecond precision +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +pub struct StdMillisecondsDuration(*mut c_void, PhantomData<()>); + +/// A wrapper arond a c++ duration with second precision. +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +pub struct StdSecondsDuration(*mut c_void, PhantomData<()>); + +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +impl StdMillisecondsDuration { + /// Construct a millisecond duration from its tick count. + fn from_count(milliseconds: c_longlong) -> Self { + let duration = unsafe { + cpp!([milliseconds as "long long"] -> *mut c_void as + "TestDuration*" { + return new TestDuration(milliseconds); + }) + }; + Self(duration, PhantomData) + } + + /// Return the number of milliseconds in the duration. + fn count(&self) -> c_longlong { + let duration = self.0 as *const c_void; + + unsafe { + cpp!([duration as "const TestDuration*"] -> c_longlong as + "long long" { + return duration->count(); + }) + } + } +} + +#[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +impl StdSecondsDuration { + /// Rerturn the number of seconds in the duration. + fn count(&self) -> c_longlong { + let duration = self.0 as *const c_void; + + unsafe { + cpp!([duration as "const TestSecondsDuration*"] -> c_longlong as + "long long" { + return duration->count(); + }) + } + } +} + #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] impl StdSecondsTimePoint { /// Construct a time point from seconds since the epoch. - fn from_seconds(seconds: i64) -> Self { + fn from_seconds(seconds: c_longlong) -> Self { let point = unsafe { cpp!([seconds as "long long"] -> *mut c_void as "TestSecondsTimePoint*" { @@ -51,10 +102,21 @@ impl StdSecondsTimePoint { Self(point, PhantomData) } + + fn seconds_since_epoch(&self) -> c_longlong { + let point = self.0 as *const c_void; + + unsafe { + cpp!([point as "const TestSecondsTimePoint*"] -> c_longlong as + "long long" { + return point->time_since_epoch().count(); + }) + } + } } #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] -impl StdTimePoint { +impl StdMillisecondsTimePoint { /// Construct a time point at the clock's epoch. fn default() -> Self { let point = unsafe { @@ -67,7 +129,7 @@ impl StdTimePoint { } /// Construct a time point from milliseconds since the epoch. - fn from_duration(milliseconds: i64) -> Self { + fn from_duration(milliseconds: c_longlong) -> Self { let point = unsafe { cpp!([milliseconds as "long long"] -> *mut c_void as "TestTimePoint*" { @@ -96,7 +158,7 @@ impl StdTimePoint { } /// Return the number of milliseconds since epoch. - fn milliseconds_since_epoch(&self) -> i64 { + fn milliseconds_since_epoch(&self) -> c_longlong { let point = self.0 as *const c_void; unsafe { @@ -106,6 +168,129 @@ impl StdTimePoint { }) } } + /// Round millisecond duration + fn round_duration(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + let duration = duration.0 as *const c_void; + + let result = unsafe { + cpp!([duration as "const TestDuration*"] -> *mut c_void as + "TestSecondsDuration*" { + return new TestSecondsDuration( + std::chrono::round(*duration) + ); + }) + }; + + StdSecondsDuration(result, PhantomData) + } + + /// Round millisecond timepoint + fn round_point(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + let point = point.0 as *const c_void; + + let result = unsafe { + cpp!([point as "const TestTimePoint*"] -> *mut c_void as + "TestSecondsTimePoint*" { + return new TestSecondsTimePoint( + std::chrono::round(*point) + ); + }) + }; + + StdSecondsTimePoint(result, PhantomData) + } + + /// Round millisecond duration down to whole seconds. + fn floor_duration(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + let duration = duration.0 as *const c_void; + + let result = unsafe { + cpp!([duration as "const TestDuration*"] -> *mut c_void as + "TestSecondsDuration*" { + return new TestSecondsDuration( + std::chrono::floor(*duration) + ); + }) + }; + + StdSecondsDuration(result, PhantomData) + } + + /// Round milisecond time point down to whole seconds. + fn floor_point(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + let point = point.0 as *const c_void; + + let result = unsafe { + cpp!([point as "const TestTimePoint*"] -> *mut c_void as + "TestSecondsTimePoint*" { + return new TestSecondsTimePoint( + std::chrono::floor(*point) + ); + }) + }; + + StdSecondsTimePoint(result, PhantomData) + } + + /// Round millisecond duration up to whole seonds. + fn ceil_duration(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + let duration = duration.0 as *const c_void; + + let result = unsafe { + cpp!([duration as "const TestDuration*"] -> *mut c_void as + "TestSecondsDuration*" { + return new TestSecondsDuration( + std::chrono::ceil(*duration) + ); + }) + }; + StdSecondsDuration(result, PhantomData) + } + + /// Round a millisecond time point up to whole seconsd. + fn ceil_point(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + let point = point.0 as *const c_void; + + let result = unsafe { + cpp!([point as "const TestTimePoint*"] -> *mut c_void as + "TestSecondsTimePoint*" { + return new TestSecondsTimePoint( + std::chrono::ceil(*point) + ); + }) + }; + + StdSecondsTimePoint(result, PhantomData) + } + + /// Convert seconds to milliseconds. + fn cast_seconds_to_milliseconds(point: &StdSecondsTimePoint) -> StdMillisecondsTimePoint { + let point = point.0 as *const c_void; + let result = unsafe { + cpp!([point as "const TestSecondsTimePoint*"] -> *mut c_void as + "TestTimePoint*" { + return new TestTimePoint( + std::chrono::time_point_cast(*point) + ); + }) + }; + StdMillisecondsTimePoint(result, PhantomData) + } + + /// Convert milliseconds to seconds + fn cast_milliseconds_to_seconds(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + let point = point.0 as *const c_void; + let result = unsafe { + cpp!([point as "const TestTimePoint*"] -> *mut c_void as + "TestSecondsTimePoint*" { + return new TestSecondsTimePoint( + std::chrono::time_point_cast(*point) + ); + }) + }; + + StdSecondsTimePoint(result, PhantomData) + } } // ### Ergonomics @@ -114,20 +299,79 @@ impl StdTimePoint { // Rust does not normallly support constructor overloading. // The overload! macro allows these constructors to share the name new. overload! { - impl StdTimePoint { + impl StdMillisecondsTimePoint { /// Construct time point at clock's epoch. - pub fn new() -> StdTimePoint { - StdTimePoint::default() + pub fn new() -> StdMillisecondsTimePoint { + StdMillisecondsTimePoint::default() } /// Construct time point from milliseconds since the epoch. - pub fn new(milliseconds: i64) -> StdTimePoint { - StdTimePoint::from_duration(milliseconds) + pub fn new(milliseconds: &StdMillisecondsDuration) -> StdMillisecondsTimePoint { + StdMillisecondsTimePoint::from_duration(milliseconds.count()) } /// Construct time point from seconds-resolution time point. - pub fn new(other: &StdSecondsTimePoint) -> StdTimePoint { - StdTimePoint::from_other(other) + pub fn new(other: &StdSecondsTimePoint) -> StdMillisecondsTimePoint { + StdMillisecondsTimePoint::from_other(other) + } + } +} + +// overloading the round + +overload! { + impl StdMillisecondsTimePoint { + + pub fn round(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + StdMillisecondsTimePoint::round_duration(duration) + } + + pub fn round(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + StdMillisecondsTimePoint::round_point(point) + } + + } +} + +// overloading the floor +overload! { + impl StdMillisecondsTimePoint { + + pub fn floor(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + StdMillisecondsTimePoint::floor_duration(duration) + } + + pub fn floor(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + StdMillisecondsTimePoint::floor_point(point) + } + } +} + +// overloading the ceil +overload! { + impl StdMillisecondsTimePoint { + + pub fn ceil(duration: &StdMillisecondsDuration) -> StdSecondsDuration { + StdMillisecondsTimePoint::ceil_duration(duration) + } + + pub fn ceil(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + StdMillisecondsTimePoint::ceil_point(point) + } + } +} + +// overloading the time_point_cast + +overload! { + impl StdMillisecondsTimePoint { + + pub fn time_point_cast(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { + StdMillisecondsTimePoint::cast_milliseconds_to_seconds(point) + } + + pub fn time_point_cast(point: &StdSecondsTimePoint) -> StdMillisecondsTimePoint { + StdMillisecondsTimePoint::cast_seconds_to_milliseconds(point) } } } @@ -135,15 +379,85 @@ overload! { #[test] fn test_time_point_constructors() { // Test the default constructor. - let epoch = StdTimePoint::new(); + let epoch = StdMillisecondsTimePoint::new(); assert_eq!(epoch.milliseconds_since_epoch(), 0); // Test the duration constructor. - let milliseconds = StdTimePoint::new(1500_i64); + let duration = StdMillisecondsDuration::from_count(1500); + let milliseconds = StdMillisecondsTimePoint::new(&duration); assert_eq!(milliseconds.milliseconds_since_epoch(), 1500); // Test the converting constructor. let seconds = StdSecondsTimePoint::from_seconds(2); - let converted = StdTimePoint::new(&seconds); + let converted = StdMillisecondsTimePoint::new(&seconds); assert_eq!(converted.milliseconds_since_epoch(), 2000); } + +#[test] +fn test_round_overloads() { + //Duration overload + let duration = StdMillisecondsDuration::from_count(1500); + let rounded_duration = StdMillisecondsTimePoint::round(&duration); + assert_eq!(rounded_duration.count(), 2); + + // Time point overload. + let point = StdMillisecondsTimePoint::new(&duration); + let rounded_point = StdMillisecondsTimePoint::round(&point); + assert_eq!(rounded_point.seconds_since_epoch(), 2); + + // nearest value + let duration = StdMillisecondsDuration::from_count(2500); + let rounded_duration = StdMillisecondsTimePoint::round(&duration); + assert_eq!(rounded_duration.count(), 2); +} + +#[test] +fn test_floor_overloads() { + // Duration overload + let duration = StdMillisecondsDuration::from_count(1500); + let floored_duration = StdMillisecondsTimePoint::floor(&duration); + assert_eq!(floored_duration.count(), 1); + + // Time point overload + let point = StdMillisecondsTimePoint::new(&duration); + let floored_point = StdMillisecondsTimePoint::floor(&point); + assert_eq!(floored_point.seconds_since_epoch(), 1); + + // floor negative values + let duration = StdMillisecondsDuration::from_count(-1500); + let floored_duration = StdMillisecondsTimePoint::floor(&duration); + assert_eq!(floored_duration.count(), -2); +} + +#[test] +fn test_ceil_overloads() { + // Duration overload. + let duration = StdMillisecondsDuration::from_count(1500); + let ceiled_duration = StdMillisecondsTimePoint::ceil(&duration); + assert_eq!(ceiled_duration.count(), 2); + + // Time poitn overload. + let point = StdMillisecondsTimePoint::new(&duration); + let ceiled_point = StdMillisecondsTimePoint::ceil(&point); + assert_eq!(ceiled_point.seconds_since_epoch(), 2); + + // Ceil the values + let duration = StdMillisecondsDuration::from_count(-1500); + let ceiled_duration = StdMillisecondsTimePoint::ceil(&duration); + assert_eq!(ceiled_duration.count(), -1); +} + +#[test] +fn test_time_point_cast_overloads() { + // Milliseconds to seconds. + let duration = StdMillisecondsDuration::from_count(5756); + let milliseconds = StdMillisecondsTimePoint::new(&duration); + + let seconds = StdMillisecondsTimePoint::time_point_cast(&milliseconds); + assert_eq!(seconds.seconds_since_epoch(), 5); + + //seconds to milliseconds + let seconds = StdSecondsTimePoint::from_seconds(4); + let milliseconds = StdMillisecondsTimePoint::time_point_cast(&seconds); + assert_eq!(milliseconds.milliseconds_since_epoch(), 4000); +} From 48173dd8530344343e1d68e98d5093b4826236fc Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Tue, 20 Oct 2026 17:35:47 +0530 Subject: [PATCH 05/15] Update documentation and comments --- cpp-overload-test/src/stdcpp/time_point.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index ed2ff9b..a512c3e 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -7,6 +7,15 @@ //! C++ time points use clock and duration types. //! This test uses fixed types instead of supporting all possible types. //! +//! The round, floor and ceil methods support only the selected +//! conversions from milliseconds to seconds. The time_point_cast +//! method supports only conversions between the two time point types +//! defind in this test. +//! +//! This test focuses on selected overloads rather than reproducing +//! the complete c++ API. Overloaded oeprators, assignment operations, +//! and other excluded are outside it's scope. +//! //! [time_point]: https://en.cppreference.com/cpp/chrono/time_point #![allow(unused_braces, reason = "Generated by overload! macro")] @@ -42,7 +51,7 @@ pub struct StdSecondsTimePoint(*mut c_void, PhantomData<()>); #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] pub struct StdMillisecondsDuration(*mut c_void, PhantomData<()>); -/// A wrapper arond a c++ duration with second precision. +/// A wrapper around a c++ duration with second precision. #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] pub struct StdSecondsDuration(*mut c_void, PhantomData<()>); @@ -74,7 +83,7 @@ impl StdMillisecondsDuration { #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] impl StdSecondsDuration { - /// Rerturn the number of seconds in the duration. + /// Return the number of seconds in the duration. fn count(&self) -> c_longlong { let duration = self.0 as *const c_void; @@ -103,6 +112,7 @@ impl StdSecondsTimePoint { Self(point, PhantomData) } + /// Return the number of seconds since the epoch. fn seconds_since_epoch(&self) -> c_longlong { let point = self.0 as *const c_void; @@ -232,7 +242,7 @@ impl StdMillisecondsTimePoint { StdSecondsTimePoint(result, PhantomData) } - /// Round millisecond duration up to whole seonds. + /// Round millisecond duration up to whole seconds. fn ceil_duration(duration: &StdMillisecondsDuration) -> StdSecondsDuration { let duration = duration.0 as *const c_void; @@ -296,7 +306,7 @@ impl StdMillisecondsTimePoint { // ### Ergonomics // C++ allows constructors with the same name but different arguments. // -// Rust does not normallly support constructor overloading. +// Rust does not normally support constructor overloading. // The overload! macro allows these constructors to share the name new. overload! { impl StdMillisecondsTimePoint { @@ -436,7 +446,7 @@ fn test_ceil_overloads() { let ceiled_duration = StdMillisecondsTimePoint::ceil(&duration); assert_eq!(ceiled_duration.count(), 2); - // Time poitn overload. + // Time point overload. let point = StdMillisecondsTimePoint::new(&duration); let ceiled_point = StdMillisecondsTimePoint::ceil(&point); assert_eq!(ceiled_point.seconds_since_epoch(), 2); From 8d6ccc426c5948c94306f26228fa90dc0234df36 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Thu, 22 Oct 2026 13:08:30 +0530 Subject: [PATCH 06/15] Rename TestTimePoint and TestDuration for better readability --- cpp-overload-test/src/stdcpp/time_point.rs | 48 +++++++++++----------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index a512c3e..f459fa2 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -29,11 +29,11 @@ cpp! {{ #include using TestClock = std::chrono::system_clock; - using TestDuration = std::chrono::milliseconds; + using TestMillisecondsDuration = std::chrono::milliseconds; using TestSecondsDuration = std::chrono::seconds; - using TestTimePoint = - std::chrono::time_point; + using TestMillisecondsTimePoint = + std::chrono::time_point; using TestSecondsTimePoint = std::chrono::time_point; @@ -61,8 +61,8 @@ impl StdMillisecondsDuration { fn from_count(milliseconds: c_longlong) -> Self { let duration = unsafe { cpp!([milliseconds as "long long"] -> *mut c_void as - "TestDuration*" { - return new TestDuration(milliseconds); + "TestMillisecondsDuration*" { + return new TestMillisecondsDuration(milliseconds); }) }; Self(duration, PhantomData) @@ -73,7 +73,7 @@ impl StdMillisecondsDuration { let duration = self.0 as *const c_void; unsafe { - cpp!([duration as "const TestDuration*"] -> c_longlong as + cpp!([duration as "const TestMillisecondsDuration*"] -> c_longlong as "long long" { return duration->count(); }) @@ -130,8 +130,8 @@ impl StdMillisecondsTimePoint { /// Construct a time point at the clock's epoch. fn default() -> Self { let point = unsafe { - cpp!([] -> *mut c_void as "TestTimePoint*" { - return new TestTimePoint(); + cpp!([] -> *mut c_void as "TestMillisecondsTimePoint*" { + return new TestMillisecondsTimePoint(); }) }; @@ -142,9 +142,9 @@ impl StdMillisecondsTimePoint { fn from_duration(milliseconds: c_longlong) -> Self { let point = unsafe { cpp!([milliseconds as "long long"] -> *mut c_void as - "TestTimePoint*" { - return new TestTimePoint( - TestDuration(milliseconds) + "TestMillisecondsTimePoint*" { + return new TestMillisecondsTimePoint( + TestMillisecondsDuration(milliseconds) ); }) }; @@ -158,8 +158,8 @@ impl StdMillisecondsTimePoint { let point = unsafe { cpp!([other as "const TestSecondsTimePoint*"] -> *mut - c_void as "TestTimePoint*" { - return new TestTimePoint(*other); + c_void as "TestMillisecondsTimePoint*" { + return new TestMillisecondsTimePoint(*other); }) }; @@ -172,7 +172,7 @@ impl StdMillisecondsTimePoint { let point = self.0 as *const c_void; unsafe { - cpp!([point as "const TestTimePoint*"] -> c_longlong as + cpp!([point as "const TestMillisecondsTimePoint*"] -> c_longlong as "long long" { return point->time_since_epoch().count(); }) @@ -183,7 +183,7 @@ impl StdMillisecondsTimePoint { let duration = duration.0 as *const c_void; let result = unsafe { - cpp!([duration as "const TestDuration*"] -> *mut c_void as + cpp!([duration as "const TestMillisecondsDuration*"] -> *mut c_void as "TestSecondsDuration*" { return new TestSecondsDuration( std::chrono::round(*duration) @@ -199,7 +199,7 @@ impl StdMillisecondsTimePoint { let point = point.0 as *const c_void; let result = unsafe { - cpp!([point as "const TestTimePoint*"] -> *mut c_void as + cpp!([point as "const TestMillisecondsTimePoint*"] -> *mut c_void as "TestSecondsTimePoint*" { return new TestSecondsTimePoint( std::chrono::round(*point) @@ -215,7 +215,7 @@ impl StdMillisecondsTimePoint { let duration = duration.0 as *const c_void; let result = unsafe { - cpp!([duration as "const TestDuration*"] -> *mut c_void as + cpp!([duration as "const TestMillisecondsDuration*"] -> *mut c_void as "TestSecondsDuration*" { return new TestSecondsDuration( std::chrono::floor(*duration) @@ -231,7 +231,7 @@ impl StdMillisecondsTimePoint { let point = point.0 as *const c_void; let result = unsafe { - cpp!([point as "const TestTimePoint*"] -> *mut c_void as + cpp!([point as "const TestMillisecondsTimePoint*"] -> *mut c_void as "TestSecondsTimePoint*" { return new TestSecondsTimePoint( std::chrono::floor(*point) @@ -247,7 +247,7 @@ impl StdMillisecondsTimePoint { let duration = duration.0 as *const c_void; let result = unsafe { - cpp!([duration as "const TestDuration*"] -> *mut c_void as + cpp!([duration as "const TestMillisecondsDuration*"] -> *mut c_void as "TestSecondsDuration*" { return new TestSecondsDuration( std::chrono::ceil(*duration) @@ -262,7 +262,7 @@ impl StdMillisecondsTimePoint { let point = point.0 as *const c_void; let result = unsafe { - cpp!([point as "const TestTimePoint*"] -> *mut c_void as + cpp!([point as "const TestMillisecondsTimePoint*"] -> *mut c_void as "TestSecondsTimePoint*" { return new TestSecondsTimePoint( std::chrono::ceil(*point) @@ -278,9 +278,9 @@ impl StdMillisecondsTimePoint { let point = point.0 as *const c_void; let result = unsafe { cpp!([point as "const TestSecondsTimePoint*"] -> *mut c_void as - "TestTimePoint*" { - return new TestTimePoint( - std::chrono::time_point_cast(*point) + "TestMillisecondsTimePoint*" { + return new TestMillisecondsTimePoint( + std::chrono::time_point_cast(*point) ); }) }; @@ -291,7 +291,7 @@ impl StdMillisecondsTimePoint { fn cast_milliseconds_to_seconds(point: &StdMillisecondsTimePoint) -> StdSecondsTimePoint { let point = point.0 as *const c_void; let result = unsafe { - cpp!([point as "const TestTimePoint*"] -> *mut c_void as + cpp!([point as "const TestMillisecondsTimePoint*"] -> *mut c_void as "TestSecondsTimePoint*" { return new TestSecondsTimePoint( std::chrono::time_point_cast(*point) From f52a307f5980e021252fc5cfe0274c568245e0a0 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Wed, 28 Oct 2026 20:00:47 +0530 Subject: [PATCH 07/15] Add copy constructor and pass duration directly --- cpp-overload-test/src/stdcpp/time_point.rs | 67 +++++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index f459fa2..6502139 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -1,19 +1,14 @@ //! C++ overloads tests for [std::chrono::time_point][time_point] //! -//! This file tests three constructors that can be represented in Rust. +//! This file tests four constructors that can be represented in Rust. //! //! ### Limitations //! //! C++ time points use clock and duration types. //! This test uses fixed types instead of supporting all possible types. //! -//! The round, floor and ceil methods support only the selected -//! conversions from milliseconds to seconds. The time_point_cast -//! method supports only conversions between the two time point types -//! defind in this test. -//! //! This test focuses on selected overloads rather than reproducing -//! the complete c++ API. Overloaded oeprators, assignment operations, +//! the complete c++ API. Overloaded operators, assignment operations, //! and other excluded are outside it's scope. //! //! [time_point]: https://en.cppreference.com/cpp/chrono/time_point @@ -139,13 +134,14 @@ impl StdMillisecondsTimePoint { } /// Construct a time point from milliseconds since the epoch. - fn from_duration(milliseconds: c_longlong) -> Self { + fn from_duration(milliseconds: &StdMillisecondsDuration) -> Self { + let milliseconds = milliseconds.0 as *const c_void; + let point = unsafe { - cpp!([milliseconds as "long long"] -> *mut c_void as + cpp!([milliseconds as "const TestMillisecondsDuration*"] -> *mut c_void as "TestMillisecondsTimePoint*" { - return new TestMillisecondsTimePoint( - TestMillisecondsDuration(milliseconds) - ); + return new TestMillisecondsTimePoint(*milliseconds); + }) }; @@ -167,6 +163,20 @@ impl StdMillisecondsTimePoint { Self(point, PhantomData) } + /// Copy milliseconds time point + fn copy_from(other: &StdMillisecondsTimePoint) -> Self { + let other = other.0 as *const c_void; + + let point = unsafe { + cpp!([other as "const TestMillisecondsTimePoint*"] + -> *mut c_void as "TestMillisecondsTimePoint*" { + return new TestMillisecondsTimePoint(*other); + }) + }; + + Self(point, PhantomData) + } + /// Return the number of milliseconds since epoch. fn milliseconds_since_epoch(&self) -> c_longlong { let point = self.0 as *const c_void; @@ -317,18 +327,25 @@ overload! { /// Construct time point from milliseconds since the epoch. pub fn new(milliseconds: &StdMillisecondsDuration) -> StdMillisecondsTimePoint { - StdMillisecondsTimePoint::from_duration(milliseconds.count()) + StdMillisecondsTimePoint::from_duration(milliseconds) } /// Construct time point from seconds-resolution time point. pub fn new(other: &StdSecondsTimePoint) -> StdMillisecondsTimePoint { StdMillisecondsTimePoint::from_other(other) } + + /// copy millisecond time point + pub fn new(other: &StdMillisecondsTimePoint) -> StdMillisecondsTimePoint { + StdMillisecondsTimePoint::copy_from(other) + } } } // overloading the round - +// ### Limitations +// +// This test covers only conversions from milliseconds to seconds. overload! { impl StdMillisecondsTimePoint { @@ -344,6 +361,10 @@ overload! { } // overloading the floor +// +// ### Limitations +// +// This test covers only conversions from milliseconds to seconds. overload! { impl StdMillisecondsTimePoint { @@ -358,6 +379,10 @@ overload! { } // overloading the ceil +// +// ### Limitations +// +// This test covers only conversions from milliseconds to seconds. overload! { impl StdMillisecondsTimePoint { @@ -372,7 +397,11 @@ overload! { } // overloading the time_point_cast - +// +// ### Limitations +// +// This test covers only conversions between two timepoint types defined +// in this test. overload! { impl StdMillisecondsTimePoint { @@ -401,6 +430,14 @@ fn test_time_point_constructors() { let seconds = StdSecondsTimePoint::from_seconds(2); let converted = StdMillisecondsTimePoint::new(&seconds); assert_eq!(converted.milliseconds_since_epoch(), 2000); + + // Test the copy constructor + let original = StdMillisecondsTimePoint::new(&duration); + let copied = StdMillisecondsTimePoint::new(&original); + assert_eq!( + copied.milliseconds_since_epoch(), + original.milliseconds_since_epoch() + ); } #[test] From 47a00e4a636ff638ecf17daee960dc34e0263d83 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Tue, 3 Nov 2026 22:41:46 +0530 Subject: [PATCH 08/15] add new files for time_point step 2 --- .../examples/stdcpp-time-point.rs | 50 +++++++++++++++++++ .../examples/stdcpp-time-point.stderr | 28 +++++++++++ cpp-overload-test/src/stdcpp/time_point.rs | 11 ++-- 3 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 cpp-overload-test/examples/stdcpp-time-point.rs create mode 100644 cpp-overload-test/examples/stdcpp-time-point.stderr diff --git a/cpp-overload-test/examples/stdcpp-time-point.rs b/cpp-overload-test/examples/stdcpp-time-point.rs new file mode 100644 index 0000000..811e22a --- /dev/null +++ b/cpp-overload-test/examples/stdcpp-time-point.rs @@ -0,0 +1,50 @@ +//! Test c++ std::chrono::time_point +//! +//! Working overloads are in [time_point.rs] +//! +//! [time_point.rs]: ../src/stdcpp/time_point.rs + +#![feature(splat, tuple_trait)] +#![allow(incomplete_features)] +#![allow(unused_braces)] + +use splat_overload::overload; +use std::ffi::c_longlong; + +/// A fake Rust wrapper representing a C++ time_point. +/// +/// Using vector to represent the time point because this example only tests +/// overload compatibility. +#[expect(dead_code, reason = "Incompatible overloads can't be used")] +struct StdTimePoint(Vec); + +/// Workaround for testing identical time point types. +/// +/// The converting constructor can accept a time point with the same +/// duration type as the copy constructor. +type SameTimePoint = StdTimePoint; + +// Constructors: new(...) +// +// When copy constructor and converting constructor receive the same +// time_point type, their argument types become identical. +// +// c++ resolves this by preferring the non-template copy constructor. +// Rust cannot represent both as separate overloads. + +overload! { + impl StdTimePoint { + + /// Copy constructor + fn new(_other: &StdTimePoint) -> StdTimePoint { + todo!() + } + + /// Converting constructor + fn new(_other: &SameTimePoint) -> StdTimePoint { + todo!() + } + } +} + +pub fn main() {} diff --git a/cpp-overload-test/examples/stdcpp-time-point.stderr b/cpp-overload-test/examples/stdcpp-time-point.stderr new file mode 100644 index 0000000..75d2361 --- /dev/null +++ b/cpp-overload-test/examples/stdcpp-time-point.stderr @@ -0,0 +1,28 @@ +warning: feature `c_size_t` is declared but not used + --> cpp-overload-test/src/lib.rs:4:32 + | +4 | #![feature(splat, tuple_trait, c_size_t)] + | ^^^^^^^^ + | + = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default + +warning: `cpp-overload-test` (lib) generated 1 warning + Compiling cpp-overload-test v0.0.0 (/home/user/outreachy/contribute/rust/overloading/overloading-macros/cpp-overload-test) +error[E0119]: conflicting implementations of trait `NewArgs` for type `(&StdTimePoint,)` + --> cpp-overload-test/examples/stdcpp-time-point.rs:33:1 + | +33 | / overload! { +34 | | impl StdTimePoint { +35 | | +36 | | /// Copy constructor +... | +46 | | } + | | ^ + | | | + | |_first implementation here + | conflicting implementation for `(&StdTimePoint,)` + | + = note: this error originates in the macro `overload` (in Nightly builds, run with -Z macro-backtrace for more info) + +For more information about this error, try `rustc --explain E0119`. +error: could not compile `cpp-overload-test` (example "stdcpp-time-point") due to 1 previous error diff --git a/cpp-overload-test/src/stdcpp/time_point.rs b/cpp-overload-test/src/stdcpp/time_point.rs index 6502139..34c1a4f 100644 --- a/cpp-overload-test/src/stdcpp/time_point.rs +++ b/cpp-overload-test/src/stdcpp/time_point.rs @@ -2,11 +2,6 @@ //! //! This file tests four constructors that can be represented in Rust. //! -//! ### Limitations -//! -//! C++ time points use clock and duration types. -//! This test uses fixed types instead of supporting all possible types. -//! //! This test focuses on selected overloads rather than reproducing //! the complete c++ API. Overloaded operators, assignment operations, //! and other excluded are outside it's scope. @@ -23,6 +18,11 @@ use std::marker::PhantomData; cpp! {{ #include +// ### Limitations +// +// C++ time points use clock and duration types. +// This test uses fixed types instead of supporting all possible types. + using TestClock = std::chrono::system_clock; using TestMillisecondsDuration = std::chrono::milliseconds; using TestSecondsDuration = std::chrono::seconds; @@ -51,6 +51,7 @@ pub struct StdMillisecondsDuration(*mut c_void, PhantomData<()>); pub struct StdSecondsDuration(*mut c_void, PhantomData<()>); #[cfg_attr(not(test), expect(dead_code, reason = "Only used in tests"))] +#[cfg_attr(test, allow(dead_code))] impl StdMillisecondsDuration { /// Construct a millisecond duration from its tick count. fn from_count(milliseconds: c_longlong) -> Self { From ea373bebf7bd753e1c620de51fb35ad3900f3f0f Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Wed, 4 Nov 2026 18:11:16 +0530 Subject: [PATCH 09/15] update code formatting and results of analysis --- .../examples/stdcpp-time-point.rs | 18 +++++++++--------- .../examples/stdcpp-time-point.stderr | 8 -------- cpp-overloads-in-rust.md | 5 +++++ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/cpp-overload-test/examples/stdcpp-time-point.rs b/cpp-overload-test/examples/stdcpp-time-point.rs index 811e22a..139e4f5 100644 --- a/cpp-overload-test/examples/stdcpp-time-point.rs +++ b/cpp-overload-test/examples/stdcpp-time-point.rs @@ -33,17 +33,17 @@ type SameTimePoint = StdTimePoint; // Rust cannot represent both as separate overloads. overload! { - impl StdTimePoint { + impl StdTimePoint { - /// Copy constructor - fn new(_other: &StdTimePoint) -> StdTimePoint { - todo!() - } + /// Copy constructor + fn new(_other: &StdTimePoint) -> StdTimePoint { + todo!() + } - /// Converting constructor - fn new(_other: &SameTimePoint) -> StdTimePoint { - todo!() - } + /// Converting constructor + fn new(_other: &SameTimePoint) -> StdTimePoint { + todo!() + } } } diff --git a/cpp-overload-test/examples/stdcpp-time-point.stderr b/cpp-overload-test/examples/stdcpp-time-point.stderr index 75d2361..06372d6 100644 --- a/cpp-overload-test/examples/stdcpp-time-point.stderr +++ b/cpp-overload-test/examples/stdcpp-time-point.stderr @@ -1,11 +1,3 @@ -warning: feature `c_size_t` is declared but not used - --> cpp-overload-test/src/lib.rs:4:32 - | -4 | #![feature(splat, tuple_trait, c_size_t)] - | ^^^^^^^^ - | - = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default - warning: `cpp-overload-test` (lib) generated 1 warning Compiling cpp-overload-test v0.0.0 (/home/user/outreachy/contribute/rust/overloading/overloading-macros/cpp-overload-test) error[E0119]: conflicting implementations of trait `NewArgs` for type `(&StdTimePoint,)` diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index 0656300..4c6d848 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -29,6 +29,7 @@ See the Limitations section below the table for more details. | [forward_list] | ✅ | 🌗⚙️[^1] | 🌗⚙️?[^2] | ✅ | | [hash] | ✅ | ✅ | | | | [unordered_multiset] | ✅ | ✅⚙️[^3] | ✅ | ?[^4] | +| [time_point] | ✅ | ? | | ✅ | | TODO | ? | ? | ? | ? | Constructors: Create an instance of the class, called as `Class::Class(...)`
@@ -37,8 +38,12 @@ Modifiers: Add or change the items in a list class, called as `instance->put(... Transforms: Rearrange the items in a list class, called as `instance->sort(...)`
[forward_list]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/forward_list.rs +<<<<<<< HEAD [hash]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/hash.rs [unordered_multiset]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/unordered_multiset.rs +======= +[time_point]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/time_point.rs +>>>>>>> a9a3bb4 (update code formatting and results of analysis) [^1]: Rust and C++ iterators have different semantics, using adapter types is an ergonomic workaround. [^2]: `insert_after` and `splice_after` still need to be analysed. From f53a1c4f47dae4cac3c0e6adbc19aa1d6574ee9b Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Wed, 4 Nov 2026 18:19:57 +0530 Subject: [PATCH 10/15] add ? since i didn't checked operator related modifiers --- cpp-overloads-in-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index 4c6d848..7b77a4d 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -29,7 +29,7 @@ See the Limitations section below the table for more details. | [forward_list] | ✅ | 🌗⚙️[^1] | 🌗⚙️?[^2] | ✅ | | [hash] | ✅ | ✅ | | | | [unordered_multiset] | ✅ | ✅⚙️[^3] | ✅ | ?[^4] | -| [time_point] | ✅ | ? | | ✅ | +| [time_point] | ✅ | ? | ? | ✅ | | TODO | ? | ? | ? | ? | Constructors: Create an instance of the class, called as `Class::Class(...)`
From 6ec91d5ee9f5499df239afa743a864649f6f8fb4 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar <149191484+yalagadapavankumar@users.noreply.github.com> Date: Thu, 5 Nov 2026 21:48:17 +0530 Subject: [PATCH 11/15] update matching widths in table Co-authored-by: teor --- cpp-overloads-in-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index 7b77a4d..98cca6d 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -29,7 +29,7 @@ See the Limitations section below the table for more details. | [forward_list] | ✅ | 🌗⚙️[^1] | 🌗⚙️?[^2] | ✅ | | [hash] | ✅ | ✅ | | | | [unordered_multiset] | ✅ | ✅⚙️[^3] | ✅ | ?[^4] | -| [time_point] | ✅ | ? | ? | ✅ | +| [time_point] | ✅ | ✅ | | ✅ | | TODO | ? | ? | ? | ? | Constructors: Create an instance of the class, called as `Class::Class(...)`
From 713d5d3a59a3cdcf69543bc00c3ed8ac564fa5a7 Mon Sep 17 00:00:00 2001 From: Yalagada Pavan Kumar Date: Thu, 5 Nov 2026 21:51:17 +0530 Subject: [PATCH 12/15] Update error file and remove conflicts --- cpp-overload-test/examples/stdcpp-time-point.stderr | 13 ++++++------- cpp-overloads-in-rust.md | 6 ++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cpp-overload-test/examples/stdcpp-time-point.stderr b/cpp-overload-test/examples/stdcpp-time-point.stderr index 06372d6..da3204a 100644 --- a/cpp-overload-test/examples/stdcpp-time-point.stderr +++ b/cpp-overload-test/examples/stdcpp-time-point.stderr @@ -1,14 +1,13 @@ -warning: `cpp-overload-test` (lib) generated 1 warning Compiling cpp-overload-test v0.0.0 (/home/user/outreachy/contribute/rust/overloading/overloading-macros/cpp-overload-test) error[E0119]: conflicting implementations of trait `NewArgs` for type `(&StdTimePoint,)` - --> cpp-overload-test/examples/stdcpp-time-point.rs:33:1 + --> cpp-overload-test/examples/stdcpp-time-point.rs:35:1 | -33 | / overload! { -34 | | impl StdTimePoint { -35 | | -36 | | /// Copy constructor +35 | / overload! { +36 | | impl StdTimePoint { +37 | | +38 | | /// Copy constructor ... | -46 | | } +48 | | } | | ^ | | | | |_first implementation here diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index 98cca6d..4b3645a 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -38,12 +38,10 @@ Modifiers: Add or change the items in a list class, called as `instance->put(... Transforms: Rearrange the items in a list class, called as `instance->sort(...)`
[forward_list]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/forward_list.rs -<<<<<<< HEAD [hash]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/hash.rs -[unordered_multiset]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/unordered_multiset.rs -======= [time_point]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/time_point.rs ->>>>>>> a9a3bb4 (update code formatting and results of analysis) +[unordered_multiset]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/unordered_multiset.rs + [^1]: Rust and C++ iterators have different semantics, using adapter types is an ergonomic workaround. [^2]: `insert_after` and `splice_after` still need to be analysed. From f63a4077f5f70080ad864743406d47e9224b04ab Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 6 Nov 2026 19:21:49 +1000 Subject: [PATCH 13/15] Update cpp-overloads-in-rust.md --- cpp-overloads-in-rust.md | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index cd87b9e..c68cd35 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -44,7 +44,6 @@ Transforms: Rearrange the items in a list class, called as `instance->sort(...)` [unordered_map]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/unordered_map.rs [unordered_multiset]: https://github.com/rustfoundation/overloading-macros/blob/main/cpp-overload-test/src/stdcpp/unordered_multiset.rs - [^1]: Rust and C++ iterators have different semantics, using adapter types is an ergonomic workaround. [^2]: `insert_after` and `splice_after` still need to be analysed. [^3]: The overload macro can't overload on `&self` vs `&mut self`, which limits representing some accessor overloads. From 442eb71e7992c67b685302952f3da87a9740de53 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 6 Nov 2026 19:21:59 +1000 Subject: [PATCH 14/15] Update cpp-overloads-in-rust.md --- cpp-overloads-in-rust.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp-overloads-in-rust.md b/cpp-overloads-in-rust.md index c68cd35..7c5d0b4 100644 --- a/cpp-overloads-in-rust.md +++ b/cpp-overloads-in-rust.md @@ -30,7 +30,7 @@ See the Limitations section below the table for more details. | [hash] | ✅ | ✅ | | | | [unordered_map] | ✅ | 🌗⚙️[^5] | 🌗⚙️ | | | [unordered_multiset] | ✅ | ✅⚙️[^3] | ✅ | ?[^4] | -| [time_point] | ✅ | ✅ | | ✅ | +| [time_point] | ✅ | ✅ | | ✅ | | TODO | ? | ? | ? | ? | Constructors: Create an instance of the class, called as `Class::Class(...)`
From c46f8f8c654c8e66583d805539d452a6d8514500 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 6 Nov 2026 19:34:54 +1000 Subject: [PATCH 15/15] Remove inconsistent stderr line --- cpp-overload-test/examples/stdcpp-time-point.stderr | 1 - 1 file changed, 1 deletion(-) diff --git a/cpp-overload-test/examples/stdcpp-time-point.stderr b/cpp-overload-test/examples/stdcpp-time-point.stderr index da3204a..cbe9db7 100644 --- a/cpp-overload-test/examples/stdcpp-time-point.stderr +++ b/cpp-overload-test/examples/stdcpp-time-point.stderr @@ -1,4 +1,3 @@ - Compiling cpp-overload-test v0.0.0 (/home/user/outreachy/contribute/rust/overloading/overloading-macros/cpp-overload-test) error[E0119]: conflicting implementations of trait `NewArgs` for type `(&StdTimePoint,)` --> cpp-overload-test/examples/stdcpp-time-point.rs:35:1 |