about summary refs log tree commit diff
path: root/tvix/eval/src/lib.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-12-30T20·53+0100
committerclbot <clbot@tvl.fyi>2023-12-31T13·15+0000
commit12f9b95a2c75a757a36c4147eb011d096e8f48be (patch)
tree14ecada9404d8289564efea9a7c8c5e77bfd3951 /tvix/eval/src/lib.rs
parent4fba57c2c90f2e7b02da9187e59f8d64deef3fb2 (diff)
feat(tvix/eval): accept impl AsRef<str> for code r/7290
We're also happy to consume strings, or other owned stringy types.

Change-Id: I5bead4407976134815d8f879f9f70468e6af1dc4
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10476
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/lib.rs')
-rw-r--r--tvix/eval/src/lib.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 37db2b7bf418..ddc281323454 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -179,7 +179,11 @@ impl<'co, 'ro> Evaluation<'co, 'ro> {
     /// reporting, and for resolving relative paths in impure functions)
     /// This does not *run* the code, it only provides analysis (errors and
     /// warnings) of the compiler.
-    pub fn compile_only(mut self, code: &str, location: Option<PathBuf>) -> EvaluationResult {
+    pub fn compile_only(
+        mut self,
+        code: impl AsRef<str>,
+        location: Option<PathBuf>,
+    ) -> EvaluationResult {
         let mut result = EvaluationResult::default();
         let source = self.source_map();
 
@@ -188,14 +192,14 @@ impl<'co, 'ro> Evaluation<'co, 'ro> {
             .map(|p| p.to_string_lossy().to_string())
             .unwrap_or_else(|| "[code]".into());
 
-        let file = source.add_file(location_str, code.into());
+        let file = source.add_file(location_str, code.as_ref().to_string());
 
         let mut noop_observer = observer::NoOpObserver::default();
         let compiler_observer = self.compiler_observer.take().unwrap_or(&mut noop_observer);
 
         parse_compile_internal(
             &mut result,
-            code,
+            code.as_ref(),
             file,
             location,
             source,
@@ -211,7 +215,11 @@ impl<'co, 'ro> Evaluation<'co, 'ro> {
     /// Evaluate the provided source code, at an optional location of the source
     /// code (i.e. path to the file it was read from; used for error reporting,
     /// and for resolving relative paths in impure functions)
-    pub fn evaluate(mut self, code: &str, location: Option<PathBuf>) -> EvaluationResult {
+    pub fn evaluate(
+        mut self,
+        code: impl AsRef<str>,
+        location: Option<PathBuf>,
+    ) -> EvaluationResult {
         let mut result = EvaluationResult::default();
         let source = self.source_map();
 
@@ -220,7 +228,7 @@ impl<'co, 'ro> Evaluation<'co, 'ro> {
             .map(|p| p.to_string_lossy().to_string())
             .unwrap_or_else(|| "[code]".into());
 
-        let file = source.add_file(location_str, code.into());
+        let file = source.add_file(location_str, code.as_ref().to_string());
 
         let mut noop_observer = observer::NoOpObserver::default();
         let compiler_observer = self.compiler_observer.take().unwrap_or(&mut noop_observer);
@@ -232,7 +240,7 @@ impl<'co, 'ro> Evaluation<'co, 'ro> {
 
         let (lambda, globals) = match parse_compile_internal(
             &mut result,
-            code,
+            code.as_ref(),
             file.clone(),
             location,
             source,