UdpSocketWrapper

Struct UdpSocketWrapper 

Source
pub struct UdpSocketWrapper { /* private fields */ }
Expand description

A wrapper around std::net::UdpSocket that implements NtpUdpSocket.

This type allows standard library UDP sockets to be used with the sntpc library for making SNTP requests. It provides a simple synchronous interface suitable for blocking I/O operations.

§Example

use sntpc_net_std::UdpSocketWrapper;
use std::net::UdpSocket;

let socket = UdpSocket::bind("0.0.0.0:0").expect("Failed to bind socket");
let wrapper = UdpSocketWrapper::new(socket);
// Use wrapper with sntpc functions

Implementations§

Source§

impl UdpSocketWrapper

Source

pub fn new(socket: UdpSocket) -> Self

Creates a new UdpSocketWrapper from a std::net::UdpSocket.

§Arguments
  • socket - A UDP socket to wrap
§Example
use sntpc_net_std::UdpSocketWrapper;
use std::net::UdpSocket;

let socket = UdpSocket::bind("0.0.0.0:0").expect("Failed to bind");
let wrapper = UdpSocketWrapper::new(socket);

Trait Implementations§

Source§

impl From<UdpSocket> for UdpSocketWrapper

Source§

fn from(socket: UdpSocket) -> Self

Converts a std::net::UdpSocket into a UdpSocketWrapper.

This provides a convenient way to create a wrapper using .into() or from().

§Example
use sntpc_net_std::UdpSocketWrapper;
use std::net::UdpSocket;

let socket = UdpSocket::bind("0.0.0.0:0").expect("Failed to bind");
let wrapper: UdpSocketWrapper = socket.into();
Source§

impl NtpUdpSocket for UdpSocketWrapper

Source§

async fn send_to(&self, buf: &[u8], addr: SocketAddr) -> Result<usize>

Send the given buffer to an address provided. On success, returns the number of bytes written. Read more
Source§

async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>

Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.