pub fn try_send_to<P>(&mut self, buf: &[u8], target: P) -> io::Result<usize>
    where
        P: AsRef<Path>,
    {
        self.io.get_ref().send_to(buf, target)
    }
/// Try to send a datagram to the peer without waiting.
///
/// ```
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// use {
///     tokio::net::UnixDatagram,
///     tempfile::tempdir,
/// };
///
/// let bytes = b"bytes";
/// // We use a temporary directory so that the socket
/// // files left by the bound sockets will get cleaned up.
/// let tmp = tempdir().unwrap();
///
/// let server_path = tmp.path().join("server");
/// let mut server = UnixDatagram::bind(&server_path)?;
///
/// let client_path = tmp.path().join("client");
/// let mut client = UnixDatagram::bind(&client_path)?;
///
/// let size = client.try_send_to(bytes, &server_path)?;
/// assert_eq!(size, bytes.len());
///
/// let mut buffer = vec![0u8; 24];
/// let (size, addr) = server.try_recv_from(&mut buffer)?;
///
/// let dgram = &buffer.as_slice()[..size];
/// assert_eq!(dgram, bytes);
/// assert_eq!(addr.as_pathname().unwrap(), &client_path);
/// # Ok(())
/// # }
/// ```
Try to send a datagram to the peer without waiting.
Try to send a datagram to the peer without waiting .
pub fn try_send_to<P>(&mut self, buf: &[u8], target: P) -> io::Result<usize>
    where
        P: AsRef<Path>,
    {
        self.io.get_ref().send_to(buf, target)
    }
pub fn try_send_to < P > ( & mut self , buf : & [ u8 ] , target : P ) -> io :: Result < usize > where P : AsRef < Path > , { self . io . get_ref ( ) . send_to ( buf , target ) }
Try to send a datagram to the peer without waiting.
Try to send a datagram to the peer without waiting .
&mut self
buf
&[u8]
target
P
&mut self
buf
&[u8]
target
P
#[tokio::main]
None
async fn main() -> result<(), box<dyn std::error::error>> {
use {
tokio::net::UnixDatagram,
tempfile::tempdir,
}.

let bytes = b"bytes";
We use a temporary directory so that the socket
files left by the bound sockets will get cleaned up.
let tmp = tempdir().unwrap().

let server_path = tmp.path().join("server");
let mut server = UnixDatagram::bind(&server_path)?.

let client_path = tmp.path().join("client");
let mut client = UnixDatagram::bind(&client_path)?.

let size = client.try_send_to(bytes, &server_path)?;
assert_eq!(size, bytes.len()).

let mut buffer = vec![0u8; 24];
let (size, addr) = server.try_recv_from(&mut buffer)?.

let dgram = &buffer.as_slice()[..size];
assert_eq!(dgram, bytes);
assert_eq!(addr.as_pathname().unwrap(), &client_path).
use { tokio :: net :: UnixDatagram tempfile :: tempdir } . let bytes = b " bytes " ; We use a temporary directory so that the socket files left by the bound sockets will get cleaned up . let tmp = tempdir () . unwrap () . let server_path = tmp . path () . join ( " server " ) ; let mut server = UnixDatagram :: bind ( &server_path ) ? . let client_path = tmp . path () . join ( " client " ) ; let mut client = UnixDatagram :: bind ( &client_path ) ? . let size = client . try_send_to ( bytes &server_path ) ? ; assert_eq! ( size bytes . len () ) . let mut buffer = vec! [ 0u8 ; 24 ] ; let ( size addr ) = server . try_recv_from ( &mut buffer ) ? . let dgram = &buffer . as_slice () [ .. size ] ; assert_eq! ( dgram bytes ) ; assert_eq! ( addr . as_pathname () . unwrap () &client_path ) .
ok(())
None
}
None