gio/
socket_msg_flags.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ffi;
4use glib::{bitflags, prelude::*, translate::*, Type};
5
6bitflags::bitflags! {
7    /// Flags used in g_socket_receive_message() and g_socket_send_message().
8    /// The flags listed in the enum are some commonly available flags, but the
9    /// values used for them are the same as on the platform, and any other flags
10    /// are passed in/out as is. So to use a platform specific flag, just include
11    /// the right system header and pass in the flag.
12    #[doc(alias = "GSocketMsgFlags")]
13    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
14    pub struct SocketMsgFlags: ffi::GSocketMsgFlags {
15        /// No flags.
16        #[doc(alias = "G_SOCKET_MSG_NONE")]
17        const NONE = ffi::G_SOCKET_MSG_NONE as _;
18        /// Request to send/receive out of band data.
19        #[doc(alias = "G_SOCKET_MSG_OOB")]
20        const OOB = ffi::G_SOCKET_MSG_OOB as _;
21        /// Read data from the socket without removing it from
22        ///     the queue.
23        #[doc(alias = "G_SOCKET_MSG_PEEK")]
24        const PEEK = ffi::G_SOCKET_MSG_PEEK as _;
25        /// Don't use a gateway to send out the packet,
26        ///     only send to hosts on directly connected networks.
27        #[doc(alias = "G_SOCKET_MSG_DONTROUTE")]
28        const DONTROUTE = ffi::G_SOCKET_MSG_DONTROUTE as _;
29    }
30}
31
32#[doc(hidden)]
33impl IntoGlib for SocketMsgFlags {
34    type GlibType = ffi::GSocketMsgFlags;
35
36    #[inline]
37    fn into_glib(self) -> ffi::GSocketMsgFlags {
38        self.bits()
39    }
40}
41
42#[doc(hidden)]
43impl FromGlib<ffi::GSocketMsgFlags> for SocketMsgFlags {
44    #[inline]
45    unsafe fn from_glib(value: ffi::GSocketMsgFlags) -> Self {
46        Self::from_bits_truncate(value)
47    }
48}
49
50impl StaticType for SocketMsgFlags {
51    #[inline]
52    fn static_type() -> Type {
53        unsafe { from_glib(ffi::g_socket_msg_flags_get_type()) }
54    }
55}
56
57impl glib::value::ValueType for SocketMsgFlags {
58    type Type = Self;
59}
60
61unsafe impl<'a> glib::value::FromValue<'a> for SocketMsgFlags {
62    type Checker = glib::value::GenericValueTypeChecker<Self>;
63
64    unsafe fn from_value(value: &'a glib::Value) -> Self {
65        from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0) as i32)
66    }
67}
68
69impl ToValue for SocketMsgFlags {
70    fn to_value(&self) -> glib::Value {
71        let mut value = glib::Value::for_value_type::<Self>();
72        unsafe {
73            glib::gobject_ffi::g_value_set_flags(
74                value.to_glib_none_mut().0,
75                self.into_glib() as u32,
76            );
77        }
78        value
79    }
80
81    fn value_type(&self) -> glib::Type {
82        Self::static_type()
83    }
84}