[−][src]Struct rsntp::AsyncSntpClient
Asynchronous client instance
Only available when async feature is enabled (which is the default)
This is the main entry point of the asynchronous API.
Implementations
impl AsyncSntpClient
[src]
pub fn new() -> AsyncSntpClient
[src]
Creates a new instance with default parameters
Only available when async feature is enabled (which is the default)
Example
use rsntp::AsyncSntpClient; let client = AsyncSntpClient::new();
pub async fn synchronize<A: ToServerAddrs, '_>(
&'_ self,
server_address: A
) -> Result<SynchronizationResult, SynchroniztationError>
[src]
&'_ self,
server_address: A
) -> Result<SynchronizationResult, SynchroniztationError>
Synchronize with the server
Only available when async feature is enabled (which is the default)
Sends a request to the server and processes the reply. If no reply is received within timeout then an error is returned. If the supplied server address resolves to multiple addresses then only the first one is used.
Example
use rsntp::{AsyncSntpClient, SynchronizationResult, SynchroniztationError}; use chrono::{DateTime, Local}; async fn local_time() -> Result<SynchronizationResult, SynchroniztationError> { let client = AsyncSntpClient::new(); client.synchronize("pool.ntp.org").await }
pub fn set_timeout(&mut self, timeout: Duration)
[src]
Sets synchronization timeout
Sets the amount of time which the client waits for reply after the request has been sent. Default is 3 seconds.
Example
use rsntp::AsyncSntpClient; use std::time::Duration; let mut client = AsyncSntpClient::new(); client.set_timeout(Duration::from_secs(10));
pub fn set_bind_address(&mut self, address: SocketAddr)
[src]
Set UDP bind address
Sets the local address which is used to send/receive UDP packets. By default it is "0.0.0.0:0" which means that an IPv4 address and a port is chosen automatically.
To synchronize with IPv6 servers, you might need to set it to an IPv6 address.
Example
use rsntp::AsyncSntpClient; let mut client = AsyncSntpClient::new(); client.set_bind_address("192.168.0.1:0".parse().unwrap());
Trait Implementations
impl Default for AsyncSntpClient
[src]
Auto Trait Implementations
impl RefUnwindSafe for AsyncSntpClient
impl Send for AsyncSntpClient
impl Sync for AsyncSntpClient
impl Unpin for AsyncSntpClient
impl UnwindSafe for AsyncSntpClient
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,