Skip to main content

max / supernote-push

Apply rustfmt across the crate Formatting only, no behavior change. cargo check --all-targets passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author: Max Johnson <me@maxj.phd> · 2026-07-21 23:46 UTC
Commit: f184768d3f857bddfa193152fc523a688c42dace
Parent: 6c9bb0b
3 files changed, +49 insertions, -14 deletions
M examples/push.rs +10 -3
@@ -16,9 +16,13 @@ use supernote_push::{Reachability, Supernote};
16 16
17 17 fn main() -> Result<(), Box<dyn std::error::Error>> {
18 18 let mut args = std::env::args().skip(1);
19 - let host = args.next().ok_or("usage: push <host> <local.pdf> [remote_dir] [remote_name]")?;
19 + let host = args
20 + .next()
21 + .ok_or("usage: push <host> <local.pdf> [remote_dir] [remote_name]")?;
20 22 let local: PathBuf = args.next().ok_or("missing <local.pdf>")?.into();
21 - let remote_dir = args.next().unwrap_or_else(|| "Document/ripgrow".to_string());
23 + let remote_dir = args
24 + .next()
25 + .unwrap_or_else(|| "Document/ripgrow".to_string());
22 26 let remote_name = args.next().unwrap_or_else(|| {
23 27 local
24 28 .file_name()
@@ -47,7 +51,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
47 51 }
48 52 }
49 53
50 - println!("POST {host}/{remote_dir} (filename={remote_name}, {} bytes)", bytes.len());
54 + println!(
55 + "POST {host}/{remote_dir} (filename={remote_name}, {} bytes)",
56 + bytes.len()
57 + );
51 58 sn.push_pdf(&remote_dir, &remote_name, &bytes)?;
52 59 println!("done.");
53 60 Ok(())
M src/browse.rs +30 -8
@@ -20,7 +20,13 @@ use crate::{
20 20 client::{Entry, Reachability},
21 21 };
22 22
23 - const PATH: &AsciiSet = &CONTROLS.add(b' ').add(b'#').add(b'?').add(b'"').add(b'<').add(b'>');
23 + const PATH: &AsciiSet = &CONTROLS
24 + .add(b' ')
25 + .add(b'#')
26 + .add(b'?')
27 + .add(b'"')
28 + .add(b'<')
29 + .add(b'>');
24 30
25 31 pub(crate) fn probe(host: &str, port: u16, timeout: Duration) -> Reachability {
26 32 let url = format!("http://{host}:{port}/");
@@ -74,7 +80,11 @@ pub(crate) fn list(
74 80 })?;
75 81 let page: PageInfo = serde_json::from_str(&json)
76 82 .map_err(|e| Error::Http(format!("failed to parse listing JSON: {e}")))?;
77 - Ok(page.file_list.into_iter().map(RawEntry::into_entry).collect())
83 + Ok(page
84 + .file_list
85 + .into_iter()
86 + .map(RawEntry::into_entry)
87 + .collect())
78 88 }
79 89
80 90 fn agent(timeout: Duration) -> ureq::Agent {
@@ -146,8 +156,7 @@ fn basic(passcode: &str) -> String {
146 156 }
147 157
148 158 mod base64_stub {
149 - const TABLE: &[u8; 64] =
150 - b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
159 + const TABLE: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
151 160
152 161 pub fn encode(input: impl AsRef<[u8]>) -> String {
153 162 let input = input.as_ref();
@@ -219,7 +228,10 @@ mod tests {
219 228 #[test]
220 229 fn url_encodes_spaces_and_hashes() {
221 230 let url = build_url("10.0.0.5", 8089, "/Document/My Notes/", Some("a b#c.pdf"));
222 - assert_eq!(url, "http://10.0.0.5:8089/Document/My%20Notes/a%20b%23c.pdf");
231 + assert_eq!(
232 + url,
233 + "http://10.0.0.5:8089/Document/My%20Notes/a%20b%23c.pdf"
234 + );
223 235 }
224 236
225 237 #[test]
@@ -232,7 +244,10 @@ mod tests {
232 244
233 245 #[test]
234 246 fn url_root() {
235 - assert_eq!(build_url("10.0.0.5", 8089, "/", None), "http://10.0.0.5:8089");
247 + assert_eq!(
248 + build_url("10.0.0.5", 8089, "/", None),
249 + "http://10.0.0.5:8089"
250 + );
236 251 }
237 252
238 253 #[test]
@@ -261,7 +276,10 @@ mod tests {
261 276 #[test]
262 277 fn extracts_embedded_json_blob() {
263 278 let html = "<html>...\n const json = '{\"fileList\":[]}'\n const webInfo...</html>";
264 - assert_eq!(extract_embedded_json(html).as_deref(), Some(r#"{"fileList":[]}"#));
279 + assert_eq!(
280 + extract_embedded_json(html).as_deref(),
281 + Some(r#"{"fileList":[]}"#)
282 + );
265 283 }
266 284
267 285 #[test]
@@ -277,7 +295,11 @@ mod tests {
277 295 fn parses_real_nomad_listing_shape() {
278 296 let json = r#"{"deviceName":"Supernote Nomad","fileList":[{"date":"2026-07-19 07:39","extension":"","isDirectory":true,"name":"Document","size":0,"uri":"/Document"},{"date":"2026-07-19 07:58","extension":".pdf","isDirectory":false,"name":"guide.pdf","size":14817,"uri":"/Document/guide.pdf"}]}"#;
279 297 let page: PageInfo = serde_json::from_str(json).unwrap();
280 - let entries: Vec<Entry> = page.file_list.into_iter().map(RawEntry::into_entry).collect();
298 + let entries: Vec<Entry> = page
299 + .file_list
300 + .into_iter()
301 + .map(RawEntry::into_entry)
302 + .collect();
281 303 assert_eq!(entries.len(), 2);
282 304 assert_eq!(entries[0].name, "Document");
283 305 assert!(entries[0].is_dir);
M src/discover.rs +9 -3
@@ -14,13 +14,19 @@ pub fn discover(timeout: Duration) -> Result<Vec<Supernote>> {
14 14 let mut found: Vec<Supernote> = Vec::new();
15 15
16 16 while let Some(remaining) = deadline.checked_duration_since(Instant::now()) {
17 - let Ok(evt) = receiver.recv_timeout(remaining) else { break };
18 - let ServiceEvent::ServiceResolved(info) = evt else { continue };
17 + let Ok(evt) = receiver.recv_timeout(remaining) else {
18 + break;
19 + };
20 + let ServiceEvent::ServiceResolved(info) = evt else {
21 + continue;
22 + };
19 23
20 24 if !looks_like_supernote(info.get_fullname()) {
21 25 continue;
22 26 }
23 - let Some(addr) = info.get_addresses().iter().next() else { continue };
27 + let Some(addr) = info.get_addresses().iter().next() else {
28 + continue;
29 + };
24 30 let host = addr.to_string();
25 31 if found.iter().any(|d| d.host() == host) {
26 32 continue;