1use crate::{ffi, Cancellable};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GSeekable")]
10 pub struct Seekable(Interface<ffi::GSeekable, ffi::GSeekableIface>);
11
12 match fn {
13 type_ => || ffi::g_seekable_get_type(),
14 }
15}
16
17impl Seekable {
18 pub const NONE: Option<&'static Seekable> = None;
19}
20
21pub trait SeekableExt: IsA<Seekable> + 'static {
22 #[doc(alias = "g_seekable_can_seek")]
23 fn can_seek(&self) -> bool {
24 unsafe { from_glib(ffi::g_seekable_can_seek(self.as_ref().to_glib_none().0)) }
25 }
26
27 #[doc(alias = "g_seekable_can_truncate")]
28 fn can_truncate(&self) -> bool {
29 unsafe { from_glib(ffi::g_seekable_can_truncate(self.as_ref().to_glib_none().0)) }
30 }
31
32 #[doc(alias = "g_seekable_seek")]
33 fn seek(
34 &self,
35 offset: i64,
36 type_: glib::SeekType,
37 cancellable: Option<&impl IsA<Cancellable>>,
38 ) -> Result<(), glib::Error> {
39 unsafe {
40 let mut error = std::ptr::null_mut();
41 let is_ok = ffi::g_seekable_seek(
42 self.as_ref().to_glib_none().0,
43 offset,
44 type_.into_glib(),
45 cancellable.map(|p| p.as_ref()).to_glib_none().0,
46 &mut error,
47 );
48 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
49 if error.is_null() {
50 Ok(())
51 } else {
52 Err(from_glib_full(error))
53 }
54 }
55 }
56
57 #[doc(alias = "g_seekable_tell")]
58 fn tell(&self) -> i64 {
59 unsafe { ffi::g_seekable_tell(self.as_ref().to_glib_none().0) }
60 }
61
62 #[doc(alias = "g_seekable_truncate")]
63 fn truncate(
64 &self,
65 offset: i64,
66 cancellable: Option<&impl IsA<Cancellable>>,
67 ) -> Result<(), glib::Error> {
68 unsafe {
69 let mut error = std::ptr::null_mut();
70 let is_ok = ffi::g_seekable_truncate(
71 self.as_ref().to_glib_none().0,
72 offset,
73 cancellable.map(|p| p.as_ref()).to_glib_none().0,
74 &mut error,
75 );
76 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
77 if error.is_null() {
78 Ok(())
79 } else {
80 Err(from_glib_full(error))
81 }
82 }
83 }
84}
85
86impl<O: IsA<Seekable>> SeekableExt for O {}