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, 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
76#[cfg(feature = "v1_46")]
77#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
78impl PartialEq for AttrList {
79    #[inline]
80    fn eq(&self, other: &Self) -> bool {
81        self.equal(other)
82    }
83}
84
85#[cfg(feature = "v1_46")]
86#[cfg_attr(docsrs, doc(cfg(feature = "v1_46")))]
87impl Eq for AttrList {}
88
89#[cfg(feature = "v1_50")]
90#[cfg_attr(docsrs, doc(cfg(feature = "v1_50")))]
91impl std::str::FromStr for AttrList {
92    type Err = glib::BoolError;
93
94    fn from_str(s: &str) -> Result<Self, Self::Err> {
95        Self::from_string(s)
96    }
97}