From c554c1c1c05555528264cd8ceaa2f1e39a2c4d19 Mon Sep 17 00:00:00 2001 From: Ilan Joselevich Date: Sun, 4 Aug 2024 00:48:20 +0300 Subject: feat(tvix/eval): Implement Display for io::FileType In newer versions of Nix there's a builtins.readFileType builtin, we should try to avoid duplicating the enum -> string conversion by implementating Display before we implement builtins.readFileType. Change-Id: I579e95949a76eb33d2e7bda0000ed84859df765e Reviewed-on: https://cl.tvl.fyi/c/depot/+/12129 Reviewed-by: flokli Autosubmit: Ilan Joselevich Tested-by: BuildkiteCI --- tvix/eval/src/builtins/impure.rs | 8 +------- tvix/eval/src/io.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index c82b910f5ffa..24fe0e7e9ed4 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -9,7 +9,6 @@ use std::{ use crate::{ self as tvix_eval, errors::ErrorKind, - io::FileType, value::NixAttrs, vm::generators::{self, GenCo}, NixString, Value, @@ -60,12 +59,7 @@ mod impure_builtins { NixString::from( String::from_utf8(name.to_vec()).expect("parsing file name as string"), ), - Value::from(match ftype { - FileType::Directory => "directory", - FileType::Regular => "regular", - FileType::Symlink => "symlink", - FileType::Unknown => "unknown", - }), + Value::from(ftype.to_string()), ) }); diff --git a/tvix/eval/src/io.rs b/tvix/eval/src/io.rs index abe0e0518303..e4bad7b11ce0 100644 --- a/tvix/eval/src/io.rs +++ b/tvix/eval/src/io.rs @@ -35,6 +35,19 @@ pub enum FileType { Unknown, } +impl std::fmt::Display for FileType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let type_as_str = match &self { + FileType::Directory => "directory", + FileType::Regular => "regular", + FileType::Symlink => "symlink", + FileType::Unknown => "unknown", + }; + + write!(f, "{}", type_as_str) + } +} + /// Represents all possible filesystem interactions that exist in the Nix /// language, and that need to be executed somehow. /// -- cgit 1.4.1