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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use crate::Cancellable;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::ptr;
glib::wrapper! {
#[doc(alias = "GSeekable")]
pub struct Seekable(Interface<ffi::GSeekable, ffi::GSeekableIface>);
match fn {
type_ => || ffi::g_seekable_get_type(),
}
}
impl Seekable {
pub const NONE: Option<&'static Seekable> = None;
}
pub trait SeekableExt: 'static {
#[doc(alias = "g_seekable_can_seek")]
fn can_seek(&self) -> bool;
#[doc(alias = "g_seekable_can_truncate")]
fn can_truncate(&self) -> bool;
#[doc(alias = "g_seekable_seek")]
fn seek(
&self,
offset: i64,
type_: glib::SeekType,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), glib::Error>;
#[doc(alias = "g_seekable_tell")]
fn tell(&self) -> i64;
#[doc(alias = "g_seekable_truncate")]
fn truncate(
&self,
offset: i64,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), glib::Error>;
}
impl<O: IsA<Seekable>> SeekableExt for O {
fn can_seek(&self) -> bool {
unsafe { from_glib(ffi::g_seekable_can_seek(self.as_ref().to_glib_none().0)) }
}
fn can_truncate(&self) -> bool {
unsafe { from_glib(ffi::g_seekable_can_truncate(self.as_ref().to_glib_none().0)) }
}
fn seek(
&self,
offset: i64,
type_: glib::SeekType,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_seekable_seek(
self.as_ref().to_glib_none().0,
offset,
type_.into_glib(),
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
fn tell(&self) -> i64 {
unsafe { ffi::g_seekable_tell(self.as_ref().to_glib_none().0) }
}
fn truncate(
&self,
offset: i64,
cancellable: Option<&impl IsA<Cancellable>>,
) -> Result<(), glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let is_ok = ffi::g_seekable_truncate(
self.as_ref().to_glib_none().0,
offset,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
}
impl fmt::Display for Seekable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("Seekable")
}
}