Struct std::time::SystemTimeError
1.8.0 · source · pub struct SystemTimeError(_);
Expand description
SystemTime
的 duration_since
和 elapsed
方法返回的错误,用于了解系统时间在相反方向上的距离。
Examples
use std::thread::sleep;
use std::time::{Duration, SystemTime};
let sys_time = SystemTime::now();
sleep(Duration::from_secs(1));
let new_sys_time = SystemTime::now();
match sys_time.duration_since(new_sys_time) {
Ok(_) => {}
Err(e) => println!("SystemTimeError difference: {:?}", e.duration()),
}
RunImplementations§
source§impl SystemTimeError
impl SystemTimeError
sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
返回正时长,它表示第二个系统时间与第一个系统时间相距多远。
每当第二个系统时间表示的时间晚于调用方法的 self
的时间点时,就会从 SystemTime::duration_since
和 SystemTime::elapsed
方法返回 SystemTimeError
。
Examples
use std::thread::sleep;
use std::time::{Duration, SystemTime};
let sys_time = SystemTime::now();
sleep(Duration::from_secs(1));
let new_sys_time = SystemTime::now();
match sys_time.duration_since(new_sys_time) {
Ok(_) => {}
Err(e) => println!("SystemTimeError difference: {:?}", e.duration()),
}
RunTrait Implementations§
source§impl Clone for SystemTimeError
impl Clone for SystemTimeError
source§fn clone(&self) -> SystemTimeError
fn clone(&self) -> SystemTimeError
返回值的副本。 Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
从
source
执行复制分配。 Read moresource§impl Debug for SystemTimeError
impl Debug for SystemTimeError
source§impl Display for SystemTimeError
impl Display for SystemTimeError
Auto Trait Implementations§
impl RefUnwindSafe for SystemTimeError
impl Send for SystemTimeError
impl Sync for SystemTimeError
impl Unpin for SystemTimeError
impl UnwindSafe for SystemTimeError
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
从拥有的值中借用。 Read more