pub struct Client {
pub packet: Packet,
pub timestamp: i64,
pub src: String,
pub read_timeout: Duration,
pub write_timeout: Duration,
pub target: SocketAddr,
pub offset: Option<FixedOffset>,
pub format: Option<String>,
}
Fields§
§packet: Packet
§timestamp: i64
§src: String
§read_timeout: Duration
§write_timeout: Duration
§target: SocketAddr
§offset: Option<FixedOffset>
§format: Option<String>
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
§Example: Get time from an NTP server and sync systemtime
fn main() -> e_utils::AnyResult<()> {
let target = "0.pool.ntp.org:123";
let res = ntp_client::Client::new()
.target(target)?
.format(Some("%Y/%m/%d %H:%M:%S"))
.request()?;
let res_str = res.get_datetime_str().ok_or("error")?;
println!("UTC str -> {res_str}");
let datetime = res.get_datetime_utc().ok_or("get datetime utc")?;
ntp_client::sync_systemtime(datetime)?;
Ok(())
}
pub fn offset(self, offset: Option<FixedOffset>) -> Self
pub fn format(self, format: Option<impl Into<String>>) -> Self
pub fn target<A: ToSocketAddrs>(self, addr: A) -> AnyResult<Self>
pub fn src_ip(self, addr: impl Into<String>) -> Self
pub fn packet(self, packet: Packet) -> Self
pub fn request(self) -> AnyResult<Self>
pub fn get_datetime_utc(&self) -> Option<DateTime<Utc>>
pub fn get_datetime_shanghai(&self) -> Option<DateTime<FixedOffset>>
pub fn get_datetime_str(&self) -> Option<String>
pub fn now_zh() -> Option<DateTime<FixedOffset>>
pub fn now() -> DateTime<Utc>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
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
Mutably borrows from an owned value. Read more