// If an I/O error occurs inside serde_json, the error will include a file path // as well as what operation was being performed. letdecoded:Vec<String>=serde_json::from_reader(file)?;
mod dir; mod errors; mod file; mod open_options; pubmod os; mod path; #[cfg(feature = "tokio")] #[cfg_attr(docsrs, doc(cfg(feature = "tokio")))] pubmod tokio;
use std::fs; use std::io::{self, Read, Write}; use std::path::{Path, PathBuf};
use errors::{Error, ErrorKind, SourceDestError, SourceDestErrorKind};
/// Wrapper for [`fs::write`](https://doc.rust-lang.org/stable/std/fs/fn.write.html). pubfn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { let path = path.as_ref();
file::create(path)
.map_err(|err_gen| err_gen(path.to_path_buf()))?
.write_all(contents.as_ref())
.map_err(|err| Error::build(err, ErrorKind::Write, path))
}
/// Wrapper for [`fs::copy`](https://doc.rust-lang.org/stable/std/fs/fn.copy.html). pubfn copy<P, Q>(from: P, to: Q) -> io::Result<u64> where
P: AsRef<Path>,
Q: AsRef<Path>,
{ let from = from.as_ref(); let to = to.as_ref();
fs::copy(from, to)
.map_err(|source| SourceDestError::build(source, SourceDestErrorKind::Copy, from, to))
}
/// Wrapper for [`fs::create_dir`](https://doc.rust-lang.org/stable/std/fs/fn.create_dir.html). pubfn create_dir<P>(path: P) -> io::Result<()> where
P: AsRef<Path>,
{ let path = path.as_ref();
fs::create_dir(path).map_err(|source| Error::build(source, ErrorKind::CreateDir, path))
}
/// Wrapper for [`fs::create_dir_all`](https://doc.rust-lang.org/stable/std/fs/fn.create_dir_all.html). pubfn create_dir_all<P>(path: P) -> io::Result<()> where
P: AsRef<Path>,
{ let path = path.as_ref();
fs::create_dir_all(path).map_err(|source| Error::build(source, ErrorKind::CreateDir, path))
}
/// Wrapper for [`fs::remove_dir`](https://doc.rust-lang.org/stable/std/fs/fn.remove_dir.html). pubfn remove_dir<P>(path: P) -> io::Result<()> where
P: AsRef<Path>,
{ let path = path.as_ref();
fs::remove_dir(path).map_err(|source| Error::build(source, ErrorKind::RemoveDir, path))
}
/// Wrapper for [`fs::remove_dir_all`](https://doc.rust-lang.org/stable/std/fs/fn.remove_dir_all.html). pubfn remove_dir_all<P>(path: P) -> io::Result<()> where
P: AsRef<Path>,
{ let path = path.as_ref();
fs::remove_dir_all(path).map_err(|source| Error::build(source, ErrorKind::RemoveDir, path))
}
/// Wrapper for [`fs::remove_file`](https://doc.rust-lang.org/stable/std/fs/fn.remove_file.html). pubfn remove_file<P>(path: P) -> io::Result<()> where
P: AsRef<Path>,
{ let path = path.as_ref();
fs::remove_file(path).map_err(|source| Error::build(source, ErrorKind::RemoveFile, path))
}
/// Wrapper for [`fs::metadata`](https://doc.rust-lang.org/stable/std/fs/fn.metadata.html). pubfn metadata<P: AsRef<Path>>(path: P) -> io::Result<fs::Metadata> { let path = path.as_ref();
fs::metadata(path).map_err(|source| Error::build(source, ErrorKind::Metadata, path))
}
/// Wrapper for [`fs::canonicalize`](https://doc.rust-lang.org/stable/std/fs/fn.canonicalize.html). pubfn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> { let path = path.as_ref();
fs::canonicalize(path).map_err(|source| Error::build(source, ErrorKind::Canonicalize, path))
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.