MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / read_to_string

Function read_to_string

cranelift/src/utils.rs:10–25  ·  view source on GitHub ↗

Read an entire file into a string.

(path: P)

Source from the content-addressed store, hash-verified

8
9/// Read an entire file into a string.
10pub fn read_to_string<P: AsRef<Path>>(path: P) -> anyhow::Result<String> {
11 let mut buffer = String::new();
12 let path = path.as_ref();
13 if path == Path::new("-") {
14 let stdin = io::stdin();
15 let mut stdin = stdin.lock();
16 stdin
17 .read_to_string(&mut buffer)
18 .context("failed to read stdin to string")?;
19 } else {
20 let mut file = File::open(path)?;
21 file.read_to_string(&mut buffer)
22 .with_context(|| format!("failed to read {} to string", path.display()))?;
23 }
24 Ok(buffer)
25}
26
27/// Iterate over all of the files passed as arguments, recursively iterating through directories.
28pub fn iterate_files<'a>(files: &'a [PathBuf]) -> impl Iterator<Item = PathBuf> + 'a {

Callers 15

runFunction · 0.85
update_atMethod · 0.85
from_pathsMethod · 0.85
run_printFunction · 0.85
cat_oneFunction · 0.85
parse_inputFunction · 0.85
print_cfgFunction · 0.85
runFunction · 0.85
handle_moduleFunction · 0.85
from_pathMethod · 0.85
run_single_fileFunction · 0.85
find_and_read_clifFunction · 0.85

Calls 7

OkFunction · 0.85
with_contextMethod · 0.80
newFunction · 0.50
stdinFunction · 0.50
as_refMethod · 0.45
lockMethod · 0.45
contextMethod · 0.45

Tested by 3

run_printFunction · 0.68
profile_guestFunction · 0.68
process_expandedFunction · 0.68