pango/attr_list.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::mem;
4
5use glib::translate::*;
6
7use crate::{ffi, AttrIterator, AttrList, Attribute};
8
9impl AttrList {
10 /// Insert the given attribute into the [`AttrList`][crate::AttrList].
11 ///
12 /// It will replace any attributes of the same type
13 /// on that segment and be merged with any adjoining
14 /// attributes that are identical.
15 ///
16 /// This function is slower than [`insert()`][Self::insert()]
17 /// for creating an attribute list in order (potentially
18 /// much slower for large lists). However,
19 /// [`insert()`][Self::insert()] is not suitable for
20 /// continually changing a set of attributes since it
21 /// never removes or combines existing attributes.
22 /// ## `attr`
23 /// the attribute to insert
24 #[doc(alias = "pango_attr_list_change")]
25 pub fn change(&self, attr: impl Into<Attribute>) {
26 unsafe {
27 let attr = attr.into();
28 ffi::pango_attr_list_change(self.to_glib_none().0, attr.to_glib_none().0);
29 mem::forget(attr); //As attr transferred fully
30 }
31 }
32
33 #[cfg(feature = "v1_46")]
34 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
35 #[doc(alias = "pango_attr_list_equal")]
36 fn equal(&self, other_list: &AttrList) -> bool {
37 unsafe {
38 from_glib(ffi::pango_attr_list_equal(
39 self.to_glib_none().0,
40 other_list.to_glib_none().0,
41 ))
42 }
43 }
44
45 /// Insert the given attribute into the [`AttrList`][crate::AttrList].
46 ///
47 /// It will be inserted after all other attributes with a
48 /// matching @start_index.
49 /// ## `attr`
50 /// the attribute to insert
51 #[doc(alias = "pango_attr_list_insert")]
52 pub fn insert(&self, attr: impl Into<Attribute>) {
53 unsafe {
54 let attr = attr.into();
55 ffi::pango_attr_list_insert(self.to_glib_none().0, attr.to_glib_none().0);
56 mem::forget(attr); //As attr transferred fully
57 }
58 }
59
60 /// Insert the given attribute into the [`AttrList`][crate::AttrList].
61 ///
62 /// It will be inserted before all other attributes with a
63 /// matching @start_index.
64 /// ## `attr`
65 /// the attribute to insert
66 #[doc(alias = "pango_attr_list_insert_before")]
67 pub fn insert_before(&self, attr: impl Into<Attribute>) {
68 unsafe {
69 let attr = attr.into();
70 ffi::pango_attr_list_insert_before(self.to_glib_none().0, attr.to_glib_none().0);
71 mem::forget(attr); //As attr transferred fully
72 }
73 }
74
75 /// Create a iterator initialized to the beginning of the list.
76 ///
77 /// @self must not be modified until this iterator is freed.
78 ///
79 /// # Returns
80 ///
81 /// the newly allocated
82 /// [`AttrIterator`][crate::AttrIterator], which should be freed with
83 /// `Pango::AttrIterator::destroy()`
84 #[doc(alias = "pango_attr_list_get_iterator")]
85 #[doc(alias = "get_iterator")]
86 pub fn iterator(&self) -> AttrIterator<'_> {
87 unsafe { from_glib_full(ffi::pango_attr_list_get_iterator(self.to_glib_none().0)) }
88 }
89}
90
91#[cfg(feature = "v1_46")]
92#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
93impl PartialEq for AttrList {
94 #[inline]
95 fn eq(&self, other: &Self) -> bool {
96 self.equal(other)
97 }
98}
99
100#[cfg(feature = "v1_46")]
101#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
102impl Eq for AttrList {}
103
104#[cfg(feature = "v1_50")]
105#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
106impl std::str::FromStr for AttrList {
107 type Err = glib::BoolError;
108
109 fn from_str(s: &str) -> Result<Self, Self::Err> {
110 Self::from_string(s)
111 }
112}