From da9a6e5b782b9864b625135ebaaf4a12b9d0018e Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 16 Oct 2024 02:04:17 +0300 Subject: [PATCH] feat(tvix/eval/io): impl From for FileType Change-Id: If92ddaf3b469c4635c234b193f8d7716e11887f6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12630 Tested-by: BuildkiteCI Reviewed-by: Ilan Joselevich Autosubmit: flokli --- tvix/eval/src/io.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tvix/eval/src/io.rs b/tvix/eval/src/io.rs index 7e8b85c87..f30ef164c 100644 --- a/tvix/eval/src/io.rs +++ b/tvix/eval/src/io.rs @@ -48,6 +48,20 @@ impl std::fmt::Display for FileType { } } +impl From for FileType { + fn from(value: std::fs::FileType) -> Self { + if value.is_file() { + Self::Regular + } else if value.is_dir() { + Self::Directory + } else if value.is_symlink() { + Self::Symlink + } else { + Self::Unknown + } + } +} + /// Represents all possible filesystem interactions that exist in the Nix /// language, and that need to be executed somehow. ///