Skip to content

Commit abfbda1

Browse files
committed
explicitly name anyhow::Result
1 parent 050f809 commit abfbda1

File tree

14 files changed

+76
-79
lines changed

14 files changed

+76
-79
lines changed

src/build.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::cmd::{Command, MountKind, Runnable, SandboxBuilder};
22
use crate::prepare::Prepare;
33
use crate::{Crate, Toolchain, Workspace};
4-
use anyhow::Result;
54
use std::path::PathBuf;
65
use std::vec::Vec;
76

@@ -51,7 +50,7 @@ impl<'a> BuildBuilder<'a> {
5150
/// ```no_run
5251
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
5352
/// # use std::error::Error;
54-
/// # fn main() -> Result<(), Box<dyn Error>> {
53+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
5554
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
5655
/// # let toolchain = Toolchain::dist("");
5756
/// # let krate = Crate::local("".as_ref());
@@ -81,7 +80,7 @@ impl<'a> BuildBuilder<'a> {
8180
/// ```no_run
8281
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::{MountKind, SandboxBuilder}};
8382
/// # use std::{error::Error, path::{Path, PathBuf}};
84-
/// # fn main() -> Result<(), Box<dyn Error>> {
83+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
8584
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
8685
/// # let toolchain = Toolchain::dist("");
8786
/// # let krate = Crate::local("".as_ref());
@@ -119,7 +118,7 @@ impl<'a> BuildBuilder<'a> {
119118
/// ```no_run
120119
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
121120
/// # use std::error::Error;
122-
/// # fn main() -> Result<(), Box<dyn Error>> {
121+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
123122
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
124123
/// # let toolchain = Toolchain::dist("");
125124
/// # let krate = Crate::local("".as_ref());
@@ -131,7 +130,7 @@ impl<'a> BuildBuilder<'a> {
131130
/// })?;
132131
/// # Ok(())
133132
/// # }
134-
pub fn run<R, F: FnOnce(&Build) -> Result<R>>(self, f: F) -> Result<R> {
133+
pub fn run<R, F: FnOnce(&Build) -> anyhow::Result<R>>(self, f: F) -> anyhow::Result<R> {
135134
self.build_dir
136135
.run(self.toolchain, self.krate, self.sandbox, self.patches, f)
137136
}
@@ -153,7 +152,7 @@ impl BuildDirectory {
153152
/// ```no_run
154153
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
155154
/// # use std::error::Error;
156-
/// # fn main() -> Result<(), Box<dyn Error>> {
155+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
157156
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
158157
/// # let toolchain = Toolchain::dist("");
159158
/// # let krate = Crate::local("".as_ref());
@@ -181,14 +180,14 @@ impl BuildDirectory {
181180
}
182181
}
183182

184-
pub(crate) fn run<R, F: FnOnce(&Build) -> Result<R>>(
183+
pub(crate) fn run<R, F: FnOnce(&Build) -> anyhow::Result<R>>(
185184
&mut self,
186185
toolchain: &Toolchain,
187186
krate: &Crate,
188187
sandbox: SandboxBuilder,
189188
patches: Vec<CratePatch>,
190189
f: F,
191-
) -> Result<R> {
190+
) -> anyhow::Result<R> {
192191
let source_dir = self.source_dir();
193192
if source_dir.exists() {
194193
crate::utils::remove_dir_all(&source_dir)?;
@@ -209,7 +208,7 @@ impl BuildDirectory {
209208
}
210209

211210
/// Remove all the contents of the build directory, freeing disk space.
212-
pub fn purge(&mut self) -> Result<()> {
211+
pub fn purge(&mut self) -> anyhow::Result<()> {
213212
let build_dir = self.build_dir();
214213
if build_dir.exists() {
215214
crate::utils::remove_dir_all(&build_dir)?;
@@ -251,7 +250,7 @@ impl<'ws> Build<'ws> {
251250
/// ```no_run
252251
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
253252
/// # use std::error::Error;
254-
/// # fn main() -> Result<(), Box<dyn Error>> {
253+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
255254
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
256255
/// # let toolchain = Toolchain::dist("");
257256
/// # let krate = Crate::local("".as_ref());
@@ -288,7 +287,7 @@ impl<'ws> Build<'ws> {
288287
/// ```no_run
289288
/// # use rustwide::{WorkspaceBuilder, Toolchain, Crate, cmd::SandboxBuilder};
290289
/// # use std::error::Error;
291-
/// # fn main() -> Result<(), Box<dyn Error>> {
290+
/// # fn main() -> anyhow::Result<(), Box<dyn Error>> {
292291
/// # let workspace = WorkspaceBuilder::new("".as_ref(), "").init()?;
293292
/// # let toolchain = Toolchain::dist("");
294293
/// # let krate = Crate::local("".as_ref());
@@ -322,7 +321,7 @@ impl<'ws> Build<'ws> {
322321
/// networking is disabled.
323322
#[cfg(any(feature = "unstable", doc))]
324323
#[cfg_attr(docs_rs, doc(cfg(feature = "unstable")))]
325-
pub fn fetch_build_std_dependencies(&self, targets: &[&str]) -> Result<()> {
324+
pub fn fetch_build_std_dependencies(&self, targets: &[&str]) -> anyhow::Result<()> {
326325
crate::prepare::fetch_deps(
327326
&self.dir.workspace,
328327
self.toolchain,

src/crates/local.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::CrateTrait;
22
use crate::Workspace;
3-
use anyhow::Result;
43
use log::info;
54
use std::path::{Path, PathBuf};
65
use walkdir::WalkDir;
@@ -16,17 +15,17 @@ impl Local {
1615
}
1716

1817
impl CrateTrait for Local {
19-
fn fetch(&self, _workspace: &Workspace) -> Result<()> {
18+
fn fetch(&self, _workspace: &Workspace) -> anyhow::Result<()> {
2019
// There is no fetch to do for a local crate.
2120
Ok(())
2221
}
2322

24-
fn purge_from_cache(&self, _workspace: &Workspace) -> Result<()> {
23+
fn purge_from_cache(&self, _workspace: &Workspace) -> anyhow::Result<()> {
2524
// There is no cache to purge for a local crate.
2625
Ok(())
2726
}
2827

29-
fn copy_source_to(&self, _workspace: &Workspace, dest: &Path) -> Result<()> {
28+
fn copy_source_to(&self, _workspace: &Workspace, dest: &Path) -> anyhow::Result<()> {
3029
info!(
3130
"copying local crate from {} to {}",
3231
self.path.display(),
@@ -43,7 +42,7 @@ impl std::fmt::Display for Local {
4342
}
4443
}
4544

46-
fn copy_dir(src: &Path, dest: &Path) -> Result<()> {
45+
fn copy_dir(src: &Path, dest: &Path) -> anyhow::Result<()> {
4746
let src = crate::utils::normalize_path(src);
4847
let dest = crate::utils::normalize_path(dest);
4948

@@ -78,7 +77,7 @@ mod tests {
7877
use anyhow::Result;
7978

8079
#[test]
81-
fn test_copy_dir() -> Result<()> {
80+
fn test_copy_dir() -> anyhow::Result<()> {
8281
let tmp_src = tempfile::tempdir()?;
8382
let tmp_dest = tempfile::tempdir()?;
8483

@@ -99,7 +98,7 @@ mod tests {
9998
}
10099

101100
#[test]
102-
fn test_no_copy_target() -> Result<()> {
101+
fn test_no_copy_target() -> anyhow::Result<()> {
103102
let (src, dest) = (tempfile::tempdir()?, tempfile::tempdir()?);
104103
std::fs::create_dir(src.path().join("target"))?;
105104
std::fs::write(
@@ -116,7 +115,7 @@ mod tests {
116115
}
117116

118117
#[test]
119-
fn test_copy_symlinks() -> Result<()> {
118+
fn test_copy_symlinks() -> anyhow::Result<()> {
120119
use std::{fs, os, path::Path};
121120

122121
let tmp_src = tempfile::tempdir()?;

src/crates/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ mod local;
33
mod registry;
44

55
use crate::Workspace;
6-
use anyhow::Result;
76
use log::info;
87
use std::path::Path;
98

109
pub use registry::AlternativeRegistry;
1110

1211
trait CrateTrait: std::fmt::Display {
13-
fn fetch(&self, workspace: &Workspace) -> Result<()>;
14-
fn purge_from_cache(&self, workspace: &Workspace) -> Result<()>;
15-
fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()>;
12+
fn fetch(&self, workspace: &Workspace) -> anyhow::Result<()>;
13+
fn purge_from_cache(&self, workspace: &Workspace) -> anyhow::Result<()>;
14+
fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> anyhow::Result<()>;
1615
}
1716

1817
enum CrateType {
@@ -56,12 +55,12 @@ impl Crate {
5655

5756
/// Fetch the crate's source code and cache it in the workspace. This method will reach out to
5857
/// the network for some crate types.
59-
pub fn fetch(&self, workspace: &Workspace) -> Result<()> {
58+
pub fn fetch(&self, workspace: &Workspace) -> anyhow::Result<()> {
6059
self.as_trait().fetch(workspace)
6160
}
6261

6362
/// Remove the cached copy of this crate. The method will do nothing if the crate isn't cached.
64-
pub fn purge_from_cache(&self, workspace: &Workspace) -> Result<()> {
63+
pub fn purge_from_cache(&self, workspace: &Workspace) -> anyhow::Result<()> {
6564
self.as_trait().purge_from_cache(workspace)
6665
}
6766

@@ -75,7 +74,7 @@ impl Crate {
7574
}
7675
}
7776

78-
pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()> {
77+
pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> anyhow::Result<()> {
7978
if dest.exists() {
8079
info!(
8180
"crate source directory {} already exists, cleaning it up",

src/inside_docker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::cmd::Command;
22
use crate::workspace::Workspace;
3-
use anyhow::Result;
43
use base64::{engine::general_purpose::STANDARD as b64, Engine};
54
use getrandom::getrandom;
65
use log::info;
@@ -12,7 +11,7 @@ pub(crate) struct CurrentContainer {
1211
}
1312

1413
impl CurrentContainer {
15-
pub(crate) fn detect(workspace: &Workspace) -> Result<Option<Self>> {
14+
pub(crate) fn detect(workspace: &Workspace) -> anyhow::Result<Option<Self>> {
1615
if let Some(id) = probe_container_id(workspace)? {
1716
info!("inspecting the current container");
1817
let inspect = Command::new(workspace, "docker")
@@ -45,7 +44,7 @@ impl CurrentContainer {
4544
/// This function uses a simpler but slower method to get the ID: a file with a random string is
4645
/// created in the temp directory, the list of all the containers is fetched from Docker and then
4746
/// `cat` is executed inside each of them to check whether they have the same random string.
48-
pub(crate) fn probe_container_id(workspace: &Workspace) -> Result<Option<String>> {
47+
pub(crate) fn probe_container_id(workspace: &Workspace) -> anyhow::Result<Option<String>> {
4948
info!("detecting the ID of the container where rustwide is running");
5049

5150
// Create the probe on the current file system

src/native/unix.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::CurrentUser;
22
use crate::cmd::KillFailedError;
3-
use anyhow::Result;
43
use nix::{
54
sys::signal::{kill, Signal},
65
unistd::{Gid, Pid, Uid},
@@ -11,7 +10,7 @@ use std::path::Path;
1110

1211
const EXECUTABLE_BITS: u32 = 0o5;
1312

14-
pub(crate) fn kill_process(id: u32) -> Result<(), KillFailedError> {
13+
pub(crate) fn kill_process(id: u32) -> anyhow::Result<(), KillFailedError> {
1514
match kill(Pid::from_raw(id as i32), Signal::SIGKILL) {
1615
Ok(()) => Ok(()),
1716
Err(err) => Err(KillFailedError {
@@ -29,7 +28,7 @@ pub(crate) fn current_user() -> Option<CurrentUser> {
2928
})
3029
}
3130

32-
fn executable_mode_for(path: &Path) -> Result<u32> {
31+
fn executable_mode_for(path: &Path) -> anyhow::Result<u32> {
3332
let metadata = path.metadata()?;
3433

3534
let user = current_user().unwrap();
@@ -43,14 +42,14 @@ fn executable_mode_for(path: &Path) -> Result<u32> {
4342
}
4443
}
4544

46-
pub(crate) fn is_executable<P: AsRef<Path>>(path: P) -> Result<bool> {
45+
pub(crate) fn is_executable<P: AsRef<Path>>(path: P) -> anyhow::Result<bool> {
4746
let path = path.as_ref();
4847

4948
let expected_mode = executable_mode_for(path)?;
5049
Ok(path.metadata()?.mode() & expected_mode == expected_mode)
5150
}
5251

53-
pub(crate) fn make_executable<P: AsRef<Path>>(path: P) -> Result<()> {
52+
pub(crate) fn make_executable<P: AsRef<Path>>(path: P) -> anyhow::Result<()> {
5453
let path = path.as_ref();
5554

5655
// Set the executable and readable bits on the file

0 commit comments

Comments
 (0)