atspi_client/
text_ext.rs

1use async_trait::async_trait;
2use atspi_proxies::text::{Text, TextBlocking, TextProxy, TextProxyBlocking};
3
4impl_extended_errors!(TextProxy<'_>, TextExtError);
5impl_extended_errors!(TextProxyBlocking<'_>, TextBlockingExtError);
6
7#[allow(clippy::module_name_repetitions)]
8pub trait TextExtError: Text {
9	type Error: std::error::Error + From<<Self as Text>::Error> + Send + Sync;
10}
11
12#[allow(clippy::module_name_repetitions)]
13pub trait TextBlockingExtError: TextBlocking {
14	type Error: std::error::Error + From<<Self as TextBlocking>::Error>;
15}
16
17#[async_trait]
18pub trait TextExt: TextExtError {
19	/// Gets the full text within the accessible item.
20	/// # Errors
21	///
22	/// This may fail based on the implementation of [`Text::get_text`] or [`TextBlocking::get_text`].
23	/// With the [`TextProxy`] and [`TextProxyBlocking`] implmentations, this can fail if you ask for an invalid start or end index, or if the `DBus` method fails to send or receive.
24	async fn get_all_text(&self) -> Result<String, <Self as TextExtError>::Error>;
25}
26
27pub trait TextBlockingExt: TextBlockingExtError {
28	/// Gets the full text within the accessible item.
29	/// # Errors
30	///
31	/// This may fail based on the implementation of [`Text::get_text`] or [`TextBlocking::get_text`].
32	/// With the [`TextProxy`] and [`TextProxyBlocking`] implmentations, this can fail if you ask for an invalid start or end index, or if the `DBus` method fails to send or receive.
33	fn get_all_text(&self) -> Result<String, <Self as TextBlockingExtError>::Error>;
34}
35
36#[async_trait]
37impl<T: Text + TextExtError + Send + Sync> TextExt for T {
38	async fn get_all_text(&self) -> Result<String, <T as TextExtError>::Error> {
39		let length_of_string = self.character_count().await?;
40		Ok(self.get_text(0, length_of_string).await?)
41	}
42}
43
44impl<T: TextBlocking + TextBlockingExtError> TextBlockingExt for T {
45	fn get_all_text(&self) -> Result<String, <T as TextBlockingExtError>::Error> {
46		let length_of_string = self.character_count()?;
47		Ok(self.get_text(0, length_of_string)?)
48	}
49}
50
51assert_impl_all!(TextProxy: Text, TextExt);
52assert_impl_all!(TextProxyBlocking: TextBlocking, TextBlockingExt);