Enum UdSocketPath

Source
pub enum UdSocketPath<'a> {
    Unnamed,
    File(Cow<'a, CStr>),
    Namespaced(Cow<'a, CStr>),
}
Available on Unix only.
Expand description

Represents a name for a Unix domain socket.

The main purpose for this enumeration is to conditionally support the dedicated socket namespace on systems which implement it – for that, the Namespaced variant is used. Depending on your system, you might not be seeing it, which is when you’d need the File fallback variant, which works on all POSIX-compliant systems.

§Namespaced

This variant refers to sockets in a dedicated socket namespace, which is fully isolated from the main filesystem and closes sockets automatically when the server which opened the socket shuts down. This variant is only implemented on Linux, which is why it is not available on other POSIX-conformant systems at compile time, resulting in a compile-time error if usage is attempted.

§File

All sockets identified this way are located on the main filesystem and exist as persistent files until deletion, preventing servers from using the same socket without deleting it from the filesystem first. This variant is available on all POSIX-compilant systems.

Variants§

§

Unnamed

An unnamed socket, identified only by its file descriptor. This is an invalid path value for creating sockets – all attempts to use such a value will result in an error.

§

File(Cow<'a, CStr>)

Identifies a socket which is located in the filesystem tree, existing as a file. See the enum-level documentation for more.

§

Namespaced(Cow<'a, CStr>)

Available on Linux or Android only.

Identifies a socket in the dedicated socket namespace, where it exists until the server closes it rather than persisting as a file. See the enum-level documentation for more.

Implementations§

Source§

impl<'a> UdSocketPath<'a>

Source

pub fn as_cstr(&'a self) -> &'a CStr

Returns the path as a CStr. The resulting value does not include any indication of whether it’s a namespaced socket name or a filesystem path.

Source

pub fn as_osstr(&'a self) -> &'a OsStr

Returns the path as an OsStr. The resulting value does not include any indication of whether it’s a namespaced socket name or a filesystem path.

Source

pub fn into_cstring(self) -> CString

Returns the path as a CString. The resulting value does not include any indication of whether it’s a namespaced socket name or a filesystem path.

Source

pub fn into_osstring(self) -> OsString

Returns the path as an OsString. The resulting value does not include any indication of whether it’s a namespaced socket name or a filesystem path.

Source

pub fn make_owned(&mut self) -> bool

Ensures that the path is stored as an owned CString in place, and returns whether that required cloning or not. If self was not referring to any socket (Unnamed variant), the value is set to an empty CString (only nul terminator) of type File.

Source

pub fn to_owned(&self) -> UdSocketPath<'static>

Converts to a UdSocketPath<'static> which stores the path as an owned CString, cloning if necessary.

Source

pub fn borrow(&self) -> UdSocketPath<'_>

Borrows into another UdSocketPath<'_> instance. If borrowed here, reborrows; if owned here, returns a fresh borrow.

Source

pub fn get_cstring_mut(&mut self) -> &mut CString

Returns a mutable reference to the underlying CString, cloning the borrowed path if it wasn’t owned before.

Source

pub fn try_get_cstring_mut(&mut self) -> Option<&mut CString>

Returns a mutable reference to the underlying CString if it’s available as owned, otherwise returns None.

Source

pub const fn is_owned(&self) -> bool

Returns true if the path to the socket is stored as an owned CString, i.e. if into_cstring doesn’t require cloning the path; false otherwise.

Source§

impl UdSocketPath<'static>

Source

pub fn buffer() -> Self

Creates a buffer suitable for usage with recv_from (_ancillary/_vectored/_ancillary_vectored). The capacity is equal to the MAX_UDSOCKET_PATH_LEN constant (the nul terminator in the CString is included). The contained value is unspecified – results of reading from the buffer should not be relied upon.

§Example
use interprocess::os::unix::udsocket::{UdSocketPath, MAX_UDSOCKET_PATH_LEN};
use std::borrow::Cow;

let path_buffer = UdSocketPath::buffer();
match path_buffer {
    UdSocketPath::File(cow) => match cow {
        Cow::Owned(cstring)
    => assert_eq!(cstring.into_bytes_with_nul().capacity(), MAX_UDSOCKET_PATH_LEN),
        Cow::Borrowed(..) => unreachable!(),
    }
    _ => unreachable!(),
}
Source

pub fn file_from_vec(vec: Vec<u8>) -> Result<Self, NulError>

Constructs a UdSocketPath::File value from a Vec of bytes, wrapping CString::new.

Source

pub fn namespaced_from_vec(vec: Vec<u8>) -> Result<Self, NulError>

Available on Linux or Android only.

Constructs a UdSocketPath::Namespaced value from a Vec of bytes, wrapping CString::new.

Trait Implementations§

Source§

impl AsRef<CStr> for UdSocketPath<'_>

Source§

fn as_ref(&self) -> &CStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<OsStr> for UdSocketPath<'_>

Source§

fn as_ref(&self) -> &OsStr

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for UdSocketPath<'a>

Source§

fn clone(&self) -> UdSocketPath<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for UdSocketPath<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<UdSocketPath<'_>> for CString

Source§

fn from(path: UdSocketPath<'_>) -> Self

Converts to this type from the input type.
Source§

impl From<UdSocketPath<'_>> for OsString

Source§

fn from(path: UdSocketPath<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for UdSocketPath<'a>

Source§

fn eq(&self, other: &UdSocketPath<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> ToUdSocketPath<'a> for &'a UdSocketPath<'a>

Source§

fn to_socket_path(self) -> Result<UdSocketPath<'a>>

Reborrows an explicit UdSocketPath for a smaller lifetime.

Source§

impl<'a> ToUdSocketPath<'a> for UdSocketPath<'a>

Source§

fn to_socket_path(self) -> Result<UdSocketPath<'a>>

Accepts explicit UdSocketPaths in relevant constructors.

Source§

impl TryFrom<UdSocketPath<'_>> for sockaddr_un

Source§

type Error = Error

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

fn try_from(path: UdSocketPath<'_>) -> Result<Self>

Performs the conversion.
Source§

impl<'a> Eq for UdSocketPath<'a>

Source§

impl<'a> StructuralPartialEq for UdSocketPath<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for UdSocketPath<'a>

§

impl<'a> RefUnwindSafe for UdSocketPath<'a>

§

impl<'a> Send for UdSocketPath<'a>

§

impl<'a> Sync for UdSocketPath<'a>

§

impl<'a> Unpin for UdSocketPath<'a>

§

impl<'a> UnwindSafe for UdSocketPath<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> To for T
where T: ?Sized,

Source§

fn to<T>(self) -> T
where Self: Into<T>,

Converts to T by calling Into<T>::into.
Source§

fn try_to<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Tries to convert to T by calling TryInto<T>::try_into.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.