pub struct Time {
pub sec: i32,
pub nanosec: u32,
}Expand description
ROS Time representation
Matches builtin_interfaces/msg/Time:
sec: Seconds since epoch (signed for pre-epoch times)nanosec: Nanoseconds within the second (0-999999999)
Fields§
§sec: i32Seconds component
nanosec: u32Nanoseconds component (0-999999999)
Implementations§
Source§impl Time
impl Time
Sourcepub const fn from_nanos(nanos: i64) -> Time
pub const fn from_nanos(nanos: i64) -> Time
Create a Time from nanoseconds since epoch
Sourcepub const fn from_duration(d: Duration) -> Time
pub const fn from_duration(d: Duration) -> Time
Create a Time from a Duration (treating duration as time since epoch)
Sourcepub const fn as_duration(&self) -> Duration
pub const fn as_duration(&self) -> Duration
Convert to Duration (treating time as duration since epoch)
Sourcepub fn from_secs_f64(secs: f64) -> Time
pub fn from_secs_f64(secs: f64) -> Time
Create a Time from seconds (float)
Sourcepub fn to_secs_f64(&self) -> f64
pub fn to_secs_f64(&self) -> f64
Convert to seconds (float)
Sourcepub fn to_ros_msg<M>(&self) -> Mwhere
M: SecNanosecMsg,
pub fn to_ros_msg<M>(&self) -> Mwhere
M: SecNanosecMsg,
Stamp a generated builtin_interfaces/msg/Time — the single most common
thing a publisher does.
msg.header.stamp = node.now().to_ros_msg();The return type is inferred from the call site; any generated message
with the { sec, nanosec } field set satisfies SecNanosecMsg, which
is the same binding set the C++ Time::to_msg template has.
INFALLIBLE, deliberately. rclrs::Time::to_ros_msg returns
Result<builtin_interfaces::msg::Time, TryFromIntError> because its
Time holds i64 nanoseconds and narrowing to sec: i32 can overflow.
Ours ALREADY IS { sec: i32, nanosec: u32 }, so this is two field copies
and cannot fail. Wrapping it in a Result so a ported t.to_ros_msg()?
keeps compiling would hide a difference instead of making the compiler
point at it — the inverse of RFC-0089’s rule. A ported ? fails to
compile, locally, with one character to fix.