Fix unnecessary structure name repetitions, as reported by clippy
This commit is contained in:
committed by
Andrew Brown
parent
3f8fb37b22
commit
33b4750a64
@@ -18,43 +18,43 @@ pub(crate) enum Descriptor {
|
|||||||
|
|
||||||
impl From<OsHandle> for Descriptor {
|
impl From<OsHandle> for Descriptor {
|
||||||
fn from(handle: OsHandle) -> Self {
|
fn from(handle: OsHandle) -> Self {
|
||||||
Descriptor::OsHandle(handle)
|
Self::OsHandle(handle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<dyn VirtualFile>> for Descriptor {
|
impl From<Box<dyn VirtualFile>> for Descriptor {
|
||||||
fn from(virt: Box<dyn VirtualFile>) -> Self {
|
fn from(virt: Box<dyn VirtualFile>) -> Self {
|
||||||
Descriptor::VirtualFile(virt)
|
Self::VirtualFile(virt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Descriptor {
|
impl fmt::Debug for Descriptor {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsHandle(handle) => write!(f, "{:?}", handle),
|
Self::OsHandle(handle) => write!(f, "{:?}", handle),
|
||||||
Descriptor::VirtualFile(_) => write!(f, "VirtualFile"),
|
Self::VirtualFile(_) => write!(f, "VirtualFile"),
|
||||||
Descriptor::Stdin => write!(f, "Stdin"),
|
Self::Stdin => write!(f, "Stdin"),
|
||||||
Descriptor::Stdout => write!(f, "Stdout"),
|
Self::Stdout => write!(f, "Stdout"),
|
||||||
Descriptor::Stderr => write!(f, "Stderr"),
|
Self::Stderr => write!(f, "Stderr"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Descriptor {
|
impl Descriptor {
|
||||||
pub(crate) fn try_clone(&self) -> io::Result<Descriptor> {
|
pub(crate) fn try_clone(&self) -> io::Result<Self> {
|
||||||
match self {
|
match self {
|
||||||
Descriptor::OsHandle(file) => file.try_clone().map(|f| OsHandle::from(f).into()),
|
Self::OsHandle(file) => file.try_clone().map(|f| OsHandle::from(f).into()),
|
||||||
Descriptor::VirtualFile(virt) => virt.try_clone().map(Descriptor::VirtualFile),
|
Self::VirtualFile(virt) => virt.try_clone().map(Self::VirtualFile),
|
||||||
Descriptor::Stdin => Ok(Descriptor::Stdin),
|
Self::Stdin => Ok(Self::Stdin),
|
||||||
Descriptor::Stdout => Ok(Descriptor::Stdout),
|
Self::Stdout => Ok(Self::Stdout),
|
||||||
Descriptor::Stderr => Ok(Descriptor::Stderr),
|
Self::Stderr => Ok(Self::Stderr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a reference to the `OsHandle` or `VirtualFile` treating it as an
|
/// Return a reference to the `OsHandle` or `VirtualFile` treating it as an
|
||||||
/// actual file/dir, and allowing operations which require an actual file and
|
/// actual file/dir, and allowing operations which require an actual file and
|
||||||
/// not just a stream or socket file descriptor.
|
/// not just a stream or socket file descriptor.
|
||||||
pub(crate) fn as_file<'descriptor>(&'descriptor self) -> WasiResult<&'descriptor Descriptor> {
|
pub(crate) fn as_file<'descriptor>(&'descriptor self) -> WasiResult<&'descriptor Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::OsHandle(_) => Ok(self),
|
Self::OsHandle(_) => Ok(self),
|
||||||
Self::VirtualFile(_) => Ok(self),
|
Self::VirtualFile(_) => Ok(self),
|
||||||
@@ -65,7 +65,7 @@ impl Descriptor {
|
|||||||
/// Like `as_file`, but return a mutable reference.
|
/// Like `as_file`, but return a mutable reference.
|
||||||
pub(crate) fn as_file_mut<'descriptor>(
|
pub(crate) fn as_file_mut<'descriptor>(
|
||||||
&'descriptor mut self,
|
&'descriptor mut self,
|
||||||
) -> WasiResult<&'descriptor mut Descriptor> {
|
) -> WasiResult<&'descriptor mut Self> {
|
||||||
match self {
|
match self {
|
||||||
Self::OsHandle(_) => Ok(self),
|
Self::OsHandle(_) => Ok(self),
|
||||||
Self::VirtualFile(_) => Ok(self),
|
Self::VirtualFile(_) => Ok(self),
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub enum VirtualDirEntry {
|
|||||||
|
|
||||||
impl VirtualDirEntry {
|
impl VirtualDirEntry {
|
||||||
pub fn empty_directory() -> Self {
|
pub fn empty_directory() -> Self {
|
||||||
VirtualDirEntry::Directory(HashMap::new())
|
Self::Directory(HashMap::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,7 +313,7 @@ impl VirtualFile for InMemoryFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn try_clone(&self) -> io::Result<Box<dyn VirtualFile>> {
|
fn try_clone(&self) -> io::Result<Box<dyn VirtualFile>> {
|
||||||
Ok(Box::new(InMemoryFile {
|
Ok(Box::new(Self {
|
||||||
cursor: 0,
|
cursor: 0,
|
||||||
fd_flags: self.fd_flags,
|
fd_flags: self.fd_flags,
|
||||||
parent: Rc::clone(&self.parent),
|
parent: Rc::clone(&self.parent),
|
||||||
@@ -550,7 +550,7 @@ pub struct VirtualDir {
|
|||||||
|
|
||||||
impl VirtualDir {
|
impl VirtualDir {
|
||||||
pub fn new(writable: bool) -> Self {
|
pub fn new(writable: bool) -> Self {
|
||||||
VirtualDir {
|
Self {
|
||||||
writable,
|
writable,
|
||||||
parent: Rc::new(RefCell::new(None)),
|
parent: Rc::new(RefCell::new(None)),
|
||||||
entries: Rc::new(RefCell::new(HashMap::new())),
|
entries: Rc::new(RefCell::new(HashMap::new())),
|
||||||
@@ -558,13 +558,13 @@ impl VirtualDir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn with_dir<P: AsRef<Path>>(mut self, dir: VirtualDir, path: P) -> Self {
|
pub fn with_dir<P: AsRef<Path>>(mut self, dir: Self, path: P) -> Self {
|
||||||
self.add_dir(dir, path);
|
self.add_dir(dir, path);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn add_dir<P: AsRef<Path>>(&mut self, dir: VirtualDir, path: P) {
|
pub fn add_dir<P: AsRef<Path>>(&mut self, dir: Self, path: P) {
|
||||||
let entry = Box::new(dir);
|
let entry = Box::new(dir);
|
||||||
entry.set_parent(Some(self.try_clone().expect("can clone self")));
|
entry.set_parent(Some(self.try_clone().expect("can clone self")));
|
||||||
self.entries
|
self.entries
|
||||||
@@ -603,7 +603,7 @@ const RESERVED_ENTRY_COUNT: u32 = 2;
|
|||||||
|
|
||||||
impl VirtualFile for VirtualDir {
|
impl VirtualFile for VirtualDir {
|
||||||
fn try_clone(&self) -> io::Result<Box<dyn VirtualFile>> {
|
fn try_clone(&self) -> io::Result<Box<dyn VirtualFile>> {
|
||||||
Ok(Box::new(VirtualDir {
|
Ok(Box::new(Self {
|
||||||
writable: self.writable,
|
writable: self.writable,
|
||||||
parent: Rc::clone(&self.parent),
|
parent: Rc::clone(&self.parent),
|
||||||
entries: Rc::clone(&self.entries),
|
entries: Rc::clone(&self.entries),
|
||||||
@@ -773,7 +773,7 @@ impl VirtualFile for VirtualDir {
|
|||||||
Entry::Occupied(_) => Err(WasiError::EEXIST),
|
Entry::Occupied(_) => Err(WasiError::EEXIST),
|
||||||
Entry::Vacant(v) => {
|
Entry::Vacant(v) => {
|
||||||
if self.writable {
|
if self.writable {
|
||||||
let new_dir = Box::new(VirtualDir::new(true));
|
let new_dir = Box::new(Self::new(true));
|
||||||
new_dir.set_parent(Some(self.try_clone()?));
|
new_dir.set_parent(Some(self.try_clone()?));
|
||||||
v.insert(new_dir);
|
v.insert(new_dir);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user