1// Take a look at the license at the top of the repository in the LICENSE file.
23use std::mem;
45use glib::translate::*;
67use crate::{ffi, AttrList, Attribute};
89impl 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")]
25pub fn change(&self, attr: impl Into<Attribute>) {
26unsafe {
27let attr = attr.into();
28ffi::pango_attr_list_change(self.to_glib_none().0, attr.to_glib_none().0);
29mem::forget(attr); //As attr transferred fully
30}
31 }
3233#[cfg(feature = "v1_46")]
34 #[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
35 #[doc(alias = "pango_attr_list_equal")]
36fn equal(&self, other_list: &AttrList) -> bool {
37unsafe {
38from_glib(ffi::pango_attr_list_equal(
39self.to_glib_none().0,
40other_list.to_glib_none().0,
41 ))
42 }
43 }
4445/// 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")]
52pub fn insert(&self, attr: impl Into<Attribute>) {
53unsafe {
54let attr = attr.into();
55ffi::pango_attr_list_insert(self.to_glib_none().0, attr.to_glib_none().0);
56mem::forget(attr); //As attr transferred fully
57}
58 }
5960/// 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")]
67pub fn insert_before(&self, attr: impl Into<Attribute>) {
68unsafe {
69let attr = attr.into();
70ffi::pango_attr_list_insert_before(self.to_glib_none().0, attr.to_glib_none().0);
71mem::forget(attr); //As attr transferred fully
72}
73 }
74}
7576#[cfg(feature = "v1_46")]
77#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
78impl PartialEqfor AttrList {
79#[inline]
80fn eq(&self, other: &Self) -> bool {
81self.equal(other)
82 }
83}
8485#[cfg(feature = "v1_46")]
86#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
87impl Eqfor AttrList {}
8889#[cfg(feature = "v1_50")]
90#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
91impl std::str::FromStrfor AttrList {
92type Err = glib::BoolError;
9394fn from_str(s: &str) -> Result<Self, Self::Err> {
95Self::from_string(s)
96 }
97}