gio_win32/
output_stream.rs1#[cfg(windows)]
4use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle, RawHandle};
5
6use glib::{prelude::*, translate::*};
7
8use crate::{ffi, OutputStream};
9
10impl OutputStream {
11 #[doc(alias = "g_win32_output_stream_new")]
19 #[cfg(windows)]
20 #[cfg_attr(docsrs, doc(cfg(windows)))]
21 pub unsafe fn take_handle(handle: impl IntoRawHandle) -> OutputStream {
22 let handle = handle.into_raw_handle();
23 let close_handle = true.into_glib();
24 gio::OutputStream::from_glib_full(ffi::g_win32_output_stream_new(handle, close_handle))
25 .unsafe_cast()
26 }
27
28 #[doc(alias = "g_win32_output_stream_new")]
34 #[cfg(windows)]
35 #[cfg_attr(docsrs, doc(cfg(windows)))]
36 pub unsafe fn with_handle<T: AsRawHandle>(handle: T) -> OutputStream {
37 let handle = handle.as_raw_handle();
38 let close_handle = false.into_glib();
39 gio::OutputStream::from_glib_full(ffi::g_win32_output_stream_new(handle, close_handle))
40 .unsafe_cast()
41 }
42}
43
44#[cfg(windows)]
45#[cfg_attr(docsrs, doc(cfg(windows)))]
46impl AsRawHandle for OutputStream {
47 fn as_raw_handle(&self) -> RawHandle {
48 unsafe { ffi::g_win32_output_stream_get_handle(self.to_glib_none().0) as _ }
49 }
50}
51
52pub trait Win32OutputStreamExtManual: IsA<OutputStream> + Sized {
53 #[doc(alias = "g_win32_output_stream_get_handle")]
54 #[doc(alias = "get_handle")]
55 #[cfg(windows)]
56 #[cfg_attr(docsrs, doc(cfg(windows)))]
57 fn handle<T: FromRawHandle>(&self) -> T {
58 unsafe {
59 T::from_raw_handle(ffi::g_win32_output_stream_get_handle(
60 self.as_ref().to_glib_none().0,
61 ))
62 }
63 }
64}
65
66impl<O: IsA<OutputStream>> Win32OutputStreamExtManual for O {}