Skip to content

Commit

Permalink
Use error conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation committed Oct 30, 2024
1 parent e6f8de0 commit d1fc5d5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
12 changes: 4 additions & 8 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use_winit = ["winit", "vellogd-shared/use_winit"]

[dependencies]
libc = "0.2.155"
savvy = "*"
savvy = { git = "https://github.com/yutannihilation/savvy.git", branch = "feat/error-conversion2" }
vellogd-shared.workspace = true
vello.workspace = true
peniko.workspace = true
Expand Down
8 changes: 2 additions & 6 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@ fn save_as_png(filename: &str) -> savvy::Result<()> {
.tx
.send_event(vellogd_shared::protocol::Request::SaveAsPng {
filename: filename.into(),
})
.map_err(|_| "failed to request to write out as PNG".into())
})?;
}

#[cfg(not(feature = "use_winit"))]
{
Ok(())
}
Ok(())
}

// #[savvy]
Expand Down
11 changes: 5 additions & 6 deletions src/rust/src/vello_device/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ impl VelloGraphicsDevice {

impl WindowController for VelloGraphicsDevice {
fn send_event(&self, event: Request) -> savvy::Result<()> {
VELLO_APP_PROXY
.tx
.send_event(event)
.map_err(|e| format!("Failed to send event {e:?}").into())
VELLO_APP_PROXY.tx.send_event(event)?;
Ok(())
}

fn recv_response(&self) -> savvy::Result<Response> {
let receiver = VELLO_APP_PROXY.rx.lock().map_err(|e| e.to_string())?;
receiver.recv().map_err(|e| e.to_string().into())
let receiver = VELLO_APP_PROXY.rx.lock()?;
let res = receiver.recv()?;
Ok(res)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/rust/src/vello_device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use no_winit::VelloGraphicsDevice;

mod with_server;

use savvy::savvy_err;
use vellogd_shared::protocol::{Request, Response};
pub use with_server::VelloGraphicsDeviceWithServer;

Expand Down Expand Up @@ -73,7 +74,7 @@ pub trait WindowController {
self.send_event(Request::GetWindowSizes)?;
match self.recv_response()? {
Response::WindowSizes { width, height } => Ok((width, height)),
_ => Err("Unexpected result".into()),
_ => Err(savvy_err!("Unexpected result")),
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/rust/src/vello_device/with_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ impl VelloGraphicsDeviceWithServer {

impl WindowController for VelloGraphicsDeviceWithServer {
fn send_event(&self, event: vellogd_shared::protocol::Request) -> savvy::Result<()> {
self.tx.send(event).map_err(|e| e.to_string().into())
self.tx.send(event)?;
Ok(())
}

fn recv_response(&self) -> savvy::Result<vellogd_shared::protocol::Response> {
self.rx.recv().map_err(|e| e.to_string().into())
let res = self.rx.recv()?;
Ok(res)
}
}

Expand Down

0 comments on commit d1fc5d5

Please sign in to comment.