Format Rust sources at 100 columns

This commit is contained in:
Samuel Onoja committed 2026-10-22 01:28:03 +01:00
1 parent 4661f595f8
commit 610478f8c7
336 files changed
+23497 -7892

No files matched your search

+4 -1
View File
@@ -5,7 +5,10 @@ use serde::{Deserialize, Serialize};
pub const VERSION: u32 = 1;
pub fn now_ms() -> u64 {
let mut time = libc::timespec { tv_sec: 0, tv_nsec: 0 };
let mut time = libc::timespec {
tv_sec: 0,
tv_nsec: 0,
};
// SAFETY: time is a correctly sized writable timespec. CLOCK_BOOTTIME
// includes suspend, unlike the renderer's animation clock.
if unsafe { libc::clock_gettime(libc::CLOCK_BOOTTIME, &raw mut time) } != 0 {
+20 -6
View File
@@ -40,7 +40,8 @@ impl Connection {
command: command.into(),
args,
};
let response = write_frame(&mut self.stream, &request).and_then(|()| read_frame::<Response>(&mut self.stream));
let response = write_frame(&mut self.stream, &request)
.and_then(|()| read_frame::<Response>(&mut self.stream));
let response = match response {
Ok(response) => response,
Err(error) => {
@@ -60,7 +61,9 @@ impl Connection {
/// Wait for a server-side change; dropping the cancellation handle interrupts it.
pub fn wait(&mut self, command: &str, args: Value) -> Result<Value, String> {
self.stream.set_read_timeout(None).map_err(|e| e.to_string())?;
self.stream
.set_read_timeout(None)
.map_err(|e| e.to_string())?;
let result = self.call(command, args);
self.stream
.set_read_timeout(Some(Duration::from_secs(2)))
@@ -93,12 +96,19 @@ mod tests {
send.send(connection.wait("activity-watch", json!({"since": 7})))
.unwrap();
});
server.set_read_timeout(Some(Duration::from_secs(2))).unwrap();
server
.set_read_timeout(Some(Duration::from_secs(2)))
.unwrap();
let request: Request = read_frame(&mut server).unwrap();
assert_eq!(request.command, "activity-watch");
assert_eq!(request.args, json!({"since": 7}));
drop(cancellation);
assert!(receive.recv_timeout(Duration::from_secs(2)).unwrap().is_err());
assert!(
receive
.recv_timeout(Duration::from_secs(2))
.unwrap()
.is_err()
);
assert!(read_frame::<Request>(&mut server).is_err());
worker.join().unwrap();
}
@@ -107,8 +117,12 @@ mod tests {
fn response_identity_is_checked_before_returning_values() {
for wrong_version in [false, true] {
let (stream, mut server) = UnixStream::pair().unwrap();
server.set_read_timeout(Some(Duration::from_secs(2))).unwrap();
stream.set_read_timeout(Some(Duration::from_secs(2))).unwrap();
server
.set_read_timeout(Some(Duration::from_secs(2)))
.unwrap();
stream
.set_read_timeout(Some(Duration::from_secs(2)))
.unwrap();
let worker = std::thread::spawn(move || {
let request: Request = read_frame(&mut server).unwrap();
let mut response = Response::success(request.id, json!({}));
+4 -1
View File
@@ -79,7 +79,10 @@ impl fmt::Display for FrameError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Io(error) => error.fmt(formatter),
Self::Oversized(size) => write!(formatter, "IPC payload is {size} bytes; maximum is {MAX_PAYLOAD_SIZE}"),
Self::Oversized(size) => write!(
formatter,
"IPC payload is {size} bytes; maximum is {MAX_PAYLOAD_SIZE}"
),
Self::InvalidJson(error) => write!(formatter, "invalid IPC JSON: {error}"),
}
}
+8 -2
View File
@@ -1,7 +1,10 @@
use serde::{Deserialize, Serialize};
pub fn now_us() -> u64 {
let mut time = libc::timespec { tv_sec: 0, tv_nsec: 0 };
let mut time = libc::timespec {
tv_sec: 0,
tv_nsec: 0,
};
// CLOCK_MONOTONIC shares one epoch between the compositor and shell.
if unsafe { libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut time) } != 0 {
return 0;
@@ -100,7 +103,10 @@ impl Player {
}
let position = position.max(0.0) as u64;
Some(self.length_us.map_or(position, |length| position.min(length)))
Some(
self.length_us
.map_or(position, |length| position.min(length)),
)
}
}
+17 -4
View File
@@ -16,10 +16,17 @@ pub fn runtime_default() -> io::Result<PathBuf> {
resolve_with(None, None, std::env::var_os("XDG_RUNTIME_DIR").as_deref())
}
fn resolve_with(explicit: Option<&Path>, socket: Option<&OsStr>, runtime: Option<&OsStr>) -> io::Result<PathBuf> {
fn resolve_with(
explicit: Option<&Path>,
socket: Option<&OsStr>,
runtime: Option<&OsStr>,
) -> io::Result<PathBuf> {
if let Some(path) = explicit {
if path.as_os_str().is_empty() {
return Err(io::Error::new(io::ErrorKind::InvalidInput, "IPC socket path is empty"));
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"IPC socket path is empty",
));
}
return Ok(path.to_owned());
}
@@ -41,8 +48,14 @@ mod tests {
let runtime = Some(OsStr::new("/run/user/1000"));
let host = OsStr::new("/run/user/1000/ferese/control.sock");
let nested = Path::new("/tmp/nested/ferese/control.sock");
assert_eq!(resolve_with(Some(nested), Some(host), runtime).unwrap(), nested);
assert_eq!(resolve_with(None, Some(nested.as_os_str()), runtime).unwrap(), nested);
assert_eq!(
resolve_with(Some(nested), Some(host), runtime).unwrap(),
nested
);
assert_eq!(
resolve_with(None, Some(nested.as_os_str()), runtime).unwrap(),
nested
);
assert_eq!(resolve_with(None, None, runtime).unwrap(), Path::new(host));
assert_eq!(
resolve_with(None, Some(OsStr::new("")), runtime).unwrap(),
+12 -3
View File
@@ -22,7 +22,10 @@ pub struct Snapshot {
impl Snapshot {
/// Decode older messages with the caller's catalog. Explicit empty catalogs stay empty.
pub fn decode(mut value: Value, fallback_families: impl FnOnce() -> Vec<Family>) -> Result<Self, String> {
pub fn decode(
mut value: Value,
fallback_families: impl FnOnce() -> Vec<Family>,
) -> Result<Self, String> {
if let Some(object) = value.as_object_mut()
&& !object.contains_key("families")
{
@@ -40,7 +43,10 @@ impl Snapshot {
}
impl Connection {
pub fn get(&mut self, fallback_families: impl FnOnce() -> Vec<Family>) -> Result<Snapshot, String> {
pub fn get(
&mut self,
fallback_families: impl FnOnce() -> Vec<Family>,
) -> Result<Snapshot, String> {
Snapshot::decode(self.call("theme-get", json!({}))?, fallback_families)
}
@@ -49,6 +55,9 @@ impl Connection {
revision: u64,
fallback_families: impl FnOnce() -> Vec<Family>,
) -> Result<Snapshot, String> {
Snapshot::decode(self.wait("theme-watch", json!({"since": revision}))?, fallback_families)
Snapshot::decode(
self.wait("theme-watch", json!({"since": revision}))?,
fallback_families,
)
}
}
+4 -1
View File
@@ -89,7 +89,10 @@ mod tests {
] {
let encoded = serde_json::to_value(readiness).unwrap();
assert_eq!(encoded, json!(name));
assert_eq!(serde_json::from_value::<Readiness>(encoded).unwrap(), readiness);
assert_eq!(
serde_json::from_value::<Readiness>(encoded).unwrap(),
readiness
);
}
}