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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
use crate::{ffi};
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
use glib::{translate::*};
glib::wrapper! {
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Range(Shared<ffi::NMRange>);
match fn {
ref => |ptr| ffi::nm_range_ref(ptr),
unref => |ptr| ffi::nm_range_unref(ptr),
type_ => || ffi::nm_range_get_type(),
}
}
impl Range {
/// Creates a new #NMRange object for the given range. Setting @end
/// equal to @start creates a single-element range.
/// ## `start`
/// the first element of the range
/// ## `end`
/// the last element of the range, must be greater than or equal
/// to @start.
///
/// # Returns
///
/// the new #NMRange object.
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
#[doc(alias = "nm_range_new")]
pub fn new(start: u64, end: u64) -> Range {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::nm_range_new(start, end))
}
}
/// Compare two ranges.
/// ## `b`
/// another #NMRange
///
/// # Returns
///
/// zero if the two instances are equivalent or
/// a non-zero integer otherwise. This defines a total ordering
/// over the ranges.
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
#[doc(alias = "nm_range_cmp")]
pub fn cmp(&self, b: &Range) -> i32 {
unsafe {
ffi::nm_range_cmp(self.to_glib_none().0, b.to_glib_none().0)
}
}
/// Gets the start and end values for the range.
///
/// # Returns
///
/// [`true`] if the range contains more than one
/// element, [`false`] otherwise.
///
/// ## `start`
/// location to store the start value
///
/// ## `end`
/// location to store the end value
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
#[doc(alias = "nm_range_get_range")]
#[doc(alias = "get_range")]
pub fn range(&self) -> Option<(u64, u64)> {
unsafe {
let mut start = std::mem::MaybeUninit::uninit();
let mut end = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::nm_range_get_range(self.to_glib_none().0, start.as_mut_ptr(), end.as_mut_ptr()));
if ret { Some((start.assume_init(), end.assume_init())) } else { None }
}
}
/// Convert a `NMRange` to a string.
///
/// # Returns
///
/// a string representing the range.
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
#[doc(alias = "nm_range_to_str")]
pub fn to_str(&self) -> glib::GString {
unsafe {
from_glib_full(ffi::nm_range_to_str(self.to_glib_none().0))
}
}
/// Parses the string representation of the range to create a `NMRange`
/// instance.
/// ## `str`
/// the string representation of a range
///
/// # Returns
///
/// the `NMRange` or [`None`]
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
#[doc(alias = "nm_range_from_str")]
pub fn from_str(str: &str) -> Result<Range, glib::Error> {
assert_initialized_main_thread!();
unsafe {
let mut error = std::ptr::null_mut();
let ret = ffi::nm_range_from_str(str.to_glib_none().0, &mut error);
if error.is_null() { Ok(from_glib_full(ret)) } else { Err(from_glib_full(error)) }
}
}
}
#[cfg(feature = "v1_42")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_42")))]
impl std::fmt::Display for Range {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&self.to_str())
}
}