gio/
socket_msg_flags.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::ffi;
use glib::{bitflags, prelude::*, translate::*, Type};

bitflags::bitflags! {
    /// Flags used in g_socket_receive_message() and g_socket_send_message().
    /// The flags listed in the enum are some commonly available flags, but the
    /// values used for them are the same as on the platform, and any other flags
    /// are passed in/out as is. So to use a platform specific flag, just include
    /// the right system header and pass in the flag.
    #[doc(alias = "GSocketMsgFlags")]
    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
    pub struct SocketMsgFlags: ffi::GSocketMsgFlags {
        /// No flags.
        #[doc(alias = "G_SOCKET_MSG_NONE")]
        const NONE = ffi::G_SOCKET_MSG_NONE as _;
        /// Request to send/receive out of band data.
        #[doc(alias = "G_SOCKET_MSG_OOB")]
        const OOB = ffi::G_SOCKET_MSG_OOB as _;
        /// Read data from the socket without removing it from
        ///     the queue.
        #[doc(alias = "G_SOCKET_MSG_PEEK")]
        const PEEK = ffi::G_SOCKET_MSG_PEEK as _;
        /// Don't use a gateway to send out the packet,
        ///     only send to hosts on directly connected networks.
        #[doc(alias = "G_SOCKET_MSG_DONTROUTE")]
        const DONTROUTE = ffi::G_SOCKET_MSG_DONTROUTE as _;
    }
}

#[doc(hidden)]
impl IntoGlib for SocketMsgFlags {
    type GlibType = ffi::GSocketMsgFlags;

    #[inline]
    fn into_glib(self) -> ffi::GSocketMsgFlags {
        self.bits()
    }
}

#[doc(hidden)]
impl FromGlib<ffi::GSocketMsgFlags> for SocketMsgFlags {
    #[inline]
    unsafe fn from_glib(value: ffi::GSocketMsgFlags) -> Self {
        Self::from_bits_truncate(value)
    }
}

impl StaticType for SocketMsgFlags {
    #[inline]
    fn static_type() -> Type {
        unsafe { from_glib(ffi::g_socket_msg_flags_get_type()) }
    }
}

impl glib::value::ValueType for SocketMsgFlags {
    type Type = Self;
}

unsafe impl<'a> glib::value::FromValue<'a> for SocketMsgFlags {
    type Checker = glib::value::GenericValueTypeChecker<Self>;

    unsafe fn from_value(value: &'a glib::Value) -> Self {
        from_glib(glib::gobject_ffi::g_value_get_flags(value.to_glib_none().0) as i32)
    }
}

impl ToValue for SocketMsgFlags {
    fn to_value(&self) -> glib::Value {
        let mut value = glib::Value::for_value_type::<Self>();
        unsafe {
            glib::gobject_ffi::g_value_set_flags(
                value.to_glib_none_mut().0,
                self.into_glib() as u32,
            );
        }
        value
    }

    fn value_type(&self) -> glib::Type {
        Self::static_type()
    }
}