|
1 | | -use async_trait::async_trait; |
2 | | -use futures::prelude::*; |
3 | 1 | use gtk::glib; |
4 | 2 | use once_cell::sync::Lazy; |
5 | | -use std::borrow::Cow; |
6 | | -use std::cell::RefCell; |
7 | | -use std::rc::Rc; |
8 | | -use url::Url; |
9 | 3 |
|
10 | | -use crate::gemini; |
| 4 | +use url::Url; |
11 | 5 |
|
12 | 6 | pub static DOWNLOAD_PATH: Lazy<std::path::PathBuf> = Lazy::new(|| { |
13 | 7 | let mut download_path = glib::user_special_dir(glib::UserDirectory::Downloads) |
@@ -63,65 +57,3 @@ pub fn bookmarks_url() -> Url { |
63 | 57 | pub fn glibctx() -> glib::MainContext { |
64 | 58 | glib::MainContext::default() |
65 | 59 | } |
66 | | - |
67 | | -pub struct Color(pub u8, pub u8, pub u8); |
68 | | - |
69 | | -impl std::fmt::LowerHex for Color { |
70 | | - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
71 | | - write!(f, "{:02x}", self.0)?; |
72 | | - write!(f, "{:02x}", self.1)?; |
73 | | - write!(f, "{:02x}", self.2)?; |
74 | | - Ok(()) |
75 | | - } |
76 | | -} |
77 | | - |
78 | | -#[derive(Debug)] |
79 | | -pub enum PageElement { |
80 | | - Heading(String), |
81 | | - Quote(String), |
82 | | - Preformatted(String), |
83 | | - Text(String), |
84 | | - Link(String, Option<String>), |
85 | | - Empty, |
86 | | -} |
87 | | - |
88 | | -#[derive(Debug, Clone, PartialEq)] |
89 | | -pub struct HistoryItem { |
90 | | - pub url: url::Url, |
91 | | - pub cache: Rc<RefCell<Option<Vec<u8>>>>, |
92 | | - pub scroll_progress: f64, |
93 | | -} |
94 | | - |
95 | | -#[async_trait(?Send)] |
96 | | -pub trait LossyTextRead { |
97 | | - async fn read_line_lossy(&mut self, mut buf: &mut String) -> std::io::Result<usize>; |
98 | | -} |
99 | | - |
100 | | -#[async_trait(?Send)] |
101 | | -impl<T: AsyncBufRead + Unpin> LossyTextRead for T { |
102 | | - async fn read_line_lossy(&mut self, buf: &mut String) -> std::io::Result<usize> { |
103 | | - // FIXME: thread 'main' panicked at 'assertion failed: self.is_char_boundary(new_len)', /build/rustc-1.58.1-src/library/alloc/src/string.rs:1204:13 |
104 | | - // This is safe because we treat buf as a mut Vec to read the data, BUT, |
105 | | - // we check if it's valid utf8 using String::from_utf8_lossy. |
106 | | - // If it's not valid utf8, we swap our buf with the newly allocated and |
107 | | - // safe string returned from String::from_utf8_lossy |
108 | | - // |
109 | | - // In the implementation of BufReader::read_line, they talk about some things about |
110 | | - // panic handling, which I don't understand currently. Whatever... |
111 | | - unsafe { |
112 | | - let vec_buf = buf.as_mut_vec(); |
113 | | - let mut n = self.read_until(b'\n', vec_buf).await?; |
114 | | - |
115 | | - let correct_string = String::from_utf8_lossy(vec_buf); |
116 | | - if let Cow::Owned(valid_utf8_string) = correct_string { |
117 | | - // Yes, I know this is not good for performance because it requires useless copying. |
118 | | - // BUT, this code will only be executed when invalid utf8 is found, so i |
119 | | - // consider this as good enough |
120 | | - buf.truncate(buf.len() - n); // Remove bad non-utf8 data |
121 | | - buf.push_str(&valid_utf8_string); // Add correct utf8 data instead |
122 | | - n = valid_utf8_string.len(); |
123 | | - } |
124 | | - Ok(n) |
125 | | - } |
126 | | - } |
127 | | -} |
0 commit comments