difftreelog
style fix clippy warnings
in: master
16 files changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -5,7 +5,7 @@
use clap::{CommandFactory, Parser};
use clap_complete::Shell;
-use jrsonnet_cli::{ManifestOpts, OutputOpts, TraceOpts, MiscOpts, TlaOpts, StdOpts, GcOpts};
+use jrsonnet_cli::{GcOpts, ManifestOpts, MiscOpts, OutputOpts, StdOpts, TlaOpts, TraceOpts};
use jrsonnet_evaluator::{
apply_tla,
error::{Error as JrError, ErrorKind},
@@ -133,16 +133,14 @@
fn main_catch(opts: Opts) -> bool {
let s = State::default();
- let trace = opts
- .trace
- .trace_format();
+ let trace = opts.trace.trace_format();
if let Err(e) = main_real(&s, opts) {
if let Error::Evaluation(e) = e {
let mut out = String::new();
trace.write_trace(&mut out, &e).expect("format error");
eprintln!("{out}")
} else {
- eprintln!("{}", e);
+ eprintln!("{e}");
}
return false;
}
@@ -150,7 +148,7 @@
}
fn main_real(s: &State, opts: Opts) -> Result<(), Error> {
- let _gc_leak_guard= opts.gc.leak_on_exit();
+ let _gc_leak_guard = opts.gc.leak_on_exit();
let _gc_print_stats = opts.gc.stats_printer();
let _stack_depth_override = opts.misc.stack_size_override();
@@ -220,7 +218,7 @@
} else {
let output = val.manifest(manifest_format)?;
if !output.is_empty() {
- println!("{}", output);
+ println!("{output}");
}
}
crates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -6,7 +6,10 @@
use std::{env, marker::PhantomData, path::PathBuf};
use clap::Parser;
-use jrsonnet_evaluator::{error::Result, stack::{set_stack_depth_limit, StackDepthLimitOverrideGuard, limit_stack_depth}, FileImportResolver, State, ImportResolver};
+use jrsonnet_evaluator::{
+ stack::{limit_stack_depth, StackDepthLimitOverrideGuard},
+ FileImportResolver,
+};
use jrsonnet_gcmodule::with_thread_object_space;
pub use manifest::*;
pub use stdlib::*;
@@ -71,6 +74,7 @@
}
impl GcOpts {
pub fn stats_printer(&self) -> Option<GcStatsPrinter> {
+ #[allow(clippy::unnecessary_lazy_evaluations/*, reason = "GcStatsPrinter has side-effect on Drop"*/)]
self.gc_print_stats.then(|| GcStatsPrinter {
collect_before_printing_stats: self.gc_collect_before_printing_stats,
})
@@ -96,7 +100,7 @@
eprintln!("=== GC STATS ===");
if self.collect_before_printing_stats {
let collected = jrsonnet_gcmodule::collect_thread_cycles();
- eprintln!("Collected: {}", collected);
+ eprintln!("Collected: {collected}");
}
eprintln!("Tracked: {}", jrsonnet_gcmodule::count_thread_tracked())
}
crates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -1,10 +1,8 @@
use std::path::PathBuf;
use clap::{Parser, ValueEnum};
-use jrsonnet_evaluator::{
- error::Result,
- manifest::{JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat},
- State,
+use jrsonnet_evaluator::manifest::{
+ JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
};
use jrsonnet_stdlib::{TomlFormat, YamlFormat};
crates/jrsonnet-cli/src/stdlib.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/stdlib.rs
+++ b/crates/jrsonnet-cli/src/stdlib.rs
@@ -1,7 +1,7 @@
use std::{fs::read_to_string, str::FromStr};
use clap::Parser;
-use jrsonnet_evaluator::{error::Result, tb, trace::PathResolver, State};
+use jrsonnet_evaluator::{error::Result, trace::PathResolver, State};
use jrsonnet_stdlib::ContextInitializer;
#[derive(Clone)]
@@ -49,7 +49,7 @@
name: out[0].into(),
value: content,
}),
- Err(e) => Err(format!("{}", e)),
+ Err(e) => Err(format!("{e}")),
}
}
}
@@ -86,8 +86,7 @@
if self.no_stdlib {
return Ok(None);
}
- let ctx =
- ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
+ let ctx = ContextInitializer::new(s.clone(), PathResolver::new_cwd_fallback());
for ext in self.ext_str.iter() {
ctx.add_ext_str((&ext.name as &str).into(), (&ext.value as &str).into());
}
crates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -3,7 +3,7 @@
error::{ErrorKind, Result},
function::TlaArg,
gc::GcHashMap,
- IStr, State,
+ IStr,
};
use jrsonnet_parser::{ParserSettings, Source};
crates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -1,9 +1,5 @@
use clap::{Parser, ValueEnum};
-use jrsonnet_evaluator::{
- error::Result,
- trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat},
- State,
-};
+use jrsonnet_evaluator::trace::{CompactFormat, ExplainingFormat, PathResolver, TraceFormat};
#[derive(PartialEq, Eq, ValueEnum, Clone)]
pub enum TraceFormatName {
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -274,6 +274,7 @@
f.debug_tuple("LocError").field(&self.0).finish()
}
}
+impl std::error::Error for Error {}
pub trait ErrorSource {
fn to_location(self) -> Option<ExprLocation>;
crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -104,28 +104,15 @@
}
}
} else {
- {
- let ai = a.iter();
- let bi = b.iter();
+ let ai = a.iter();
+ let bi = b.iter();
- for (a, b) in ai.zip(bi) {
- let ord = evaluate_compare_op(&a?, &b?, op)?;
- if !ord.is_eq() {
- return Ok(ord);
- }
+ for (a, b) in ai.zip(bi) {
+ let ord = evaluate_compare_op(&a?, &b?, op)?;
+ if !ord.is_eq() {
+ return Ok(ord);
}
}
- // {
- // let ai = a.iter_expl();
- // let bi = b.iter_expl();
-
- // for (a, b) in ai.zip(bi) {
- // let ord = evaluate_compare_op(&a?, &b?, op)?;
- // if !ord.is_eq() {
- // return Ok(ord);
- // }
- // }
- // }
}
a.len().cmp(&b.len())
}
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth1//! jsonnet interpreter implementation2#![cfg_attr(feature = "nightly", feature(thread_local, type_alias_impl_trait))]3#![deny(unsafe_op_in_unsafe_fn)]4#![warn(5 clippy::all,6 clippy::nursery,7 clippy::pedantic,8 // missing_docs,9 elided_lifetimes_in_paths,10 explicit_outlives_requirements,11 noop_method_call,12 single_use_lifetimes,13 variant_size_differences,14 rustdoc::all15)]16#![allow(17 macro_expanded_macro_exports_accessed_by_absolute_paths,18 clippy::ptr_arg,19 // Too verbose20 clippy::must_use_candidate,21 // A lot of functions pass around errors thrown by code22 clippy::missing_errors_doc,23 // A lot of pointers have interior Rc24 clippy::needless_pass_by_value,25 // Its fine26 clippy::wildcard_imports,27 clippy::enum_glob_use,28 clippy::module_name_repetitions,29 // TODO: fix individual issues, however this works as intended almost everywhere30 clippy::cast_precision_loss,31 clippy::cast_possible_wrap,32 clippy::cast_possible_truncation,33 clippy::cast_sign_loss,34 // False positives35 // https://github.com/rust-lang/rust-clippy/issues/690236 clippy::use_self,37 // https://github.com/rust-lang/rust-clippy/issues/853938 clippy::iter_with_drain,39 // ci is being run with nightly, but library should work on stable40 clippy::missing_const_for_fn,41)]4243// For jrsonnet-macros44extern crate self as jrsonnet_evaluator;4546mod arr;47#[cfg(feature = "async-import")]48pub mod async_import;49mod ctx;50mod dynamic;51pub mod error;52mod evaluate;53pub mod function;54pub mod gc;55mod import;56mod integrations;57pub mod manifest;58mod map;59mod obj;60pub mod stack;61pub mod stdlib;62mod tla;63pub mod trace;64pub mod typed;65pub mod val;6667use std::{68 any::Any,69 cell::{Ref, RefCell, RefMut},70 fmt::{self, Debug},71 path::Path,72};7374pub use ctx::*;75pub use dynamic::*;76pub use error::{Error, ErrorKind::*, Result, ResultExt};77pub use evaluate::*;78use function::CallLocation;79use gc::{GcHashMap, TraceBox};80use hashbrown::hash_map::RawEntryMut;81pub use import::*;82use jrsonnet_gcmodule::{Cc, Trace};83pub use jrsonnet_interner::{IBytes, IStr};84pub use jrsonnet_parser as parser;85use jrsonnet_parser::*;86pub use obj::*;87use stack::check_depth;88pub use tla::apply_tla;89pub use val::{Thunk, Val};9091/// Thunk without bound `super`/`this`92/// object inheritance may be overriden multiple times, and will be fixed only on field read93pub trait Unbound: Trace {94 /// Type of value after object context is bound95 type Bound;96 /// Create value bound to specified object context97 fn bind(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Self::Bound>;98}99100/// Object fields may, or may not depend on `this`/`super`, this enum allows cheaper reuse of object-independent fields for native code101/// Standard jsonnet fields are always unbound102#[derive(Clone, Trace)]103pub enum MaybeUnbound {104 /// Value needs to be bound to `this`/`super`105 Unbound(Cc<TraceBox<dyn Unbound<Bound = Val>>>),106 /// Value is object-independent107 Bound(Thunk<Val>),108}109110impl Debug for MaybeUnbound {111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {112 write!(f, "MaybeUnbound")113 }114}115impl MaybeUnbound {116 /// Attach object context to value, if required117 pub fn evaluate(&self, sup: Option<ObjValue>, this: Option<ObjValue>) -> Result<Val> {118 match self {119 Self::Unbound(v) => v.bind(sup, this),120 Self::Bound(v) => Ok(v.evaluate()?),121 }122 }123}124125/// During import, this trait will be called to create initial context for file.126/// It may initialize global variables, stdlib for example.127pub trait ContextInitializer: Trace {128 /// Initialize default file context.129 fn initialize(&self, state: State, for_file: Source) -> Context;130 /// Allows upcasting from abstract to concrete context initializer.131 /// jrsonnet by itself doesn't use this method, it is allowed for it to panic.132 fn as_any(&self) -> &dyn Any;133}134135/// Context initializer which adds nothing.136#[derive(Trace)]137pub struct DummyContextInitializer;138impl ContextInitializer for DummyContextInitializer {139 fn initialize(&self, state: State, _for_file: Source) -> Context {140 ContextBuilder::new(state).build()141 }142 fn as_any(&self) -> &dyn Any {143 self144 }145}146147/// Dynamically reconfigurable evaluation settings148#[derive(Trace)]149pub struct EvaluationSettings {150 /// Context initializer, which will be used for imports and everything151 /// [`NoopContextInitializer`] is used by default, most likely you want to have `jrsonnet-stdlib`152 pub context_initializer: TraceBox<dyn ContextInitializer>,153 /// Used to resolve file locations/contents154 pub import_resolver: TraceBox<dyn ImportResolver>,155}156impl Default for EvaluationSettings {157 fn default() -> Self {158 Self {159 context_initializer: tb!(DummyContextInitializer),160 import_resolver: tb!(DummyImportResolver),161 }162 }163}164165#[derive(Trace)]166struct FileData {167 string: Option<IStr>,168 bytes: Option<IBytes>,169 parsed: Option<LocExpr>,170 evaluated: Option<Val>,171172 evaluating: bool,173}174impl FileData {175 fn new_string(data: IStr) -> Self {176 Self {177 string: Some(data),178 bytes: None,179 parsed: None,180 evaluated: None,181 evaluating: false,182 }183 }184 fn new_bytes(data: IBytes) -> Self {185 Self {186 string: None,187 bytes: Some(data),188 parsed: None,189 evaluated: None,190 evaluating: false,191 }192 }193 pub(crate) fn get_string(&mut self) -> Option<IStr> {194 if self.string.is_none() {195 self.string = Some(196 self.bytes197 .as_ref()198 .expect("either string or bytes should be set")199 .clone()200 .cast_str()?,201 );202 }203 Some(self.string.clone().expect("just set"))204 }205}206207#[derive(Default, Trace)]208pub struct EvaluationStateInternals {209 /// Internal state210 file_cache: RefCell<GcHashMap<SourcePath, FileData>>,211 /// Settings, safe to change at runtime212 settings: RefCell<EvaluationSettings>,213}214215/// Maintains stack trace and import resolution216#[derive(Default, Clone, Trace)]217pub struct State(Cc<EvaluationStateInternals>);218219impl State {220 /// Should only be called with path retrieved from [`resolve_path`], may panic otherwise221 pub fn import_resolved_str(&self, path: SourcePath) -> Result<IStr> {222 let mut file_cache = self.file_cache();223 let mut file = file_cache.raw_entry_mut().from_key(&path);224225 let file = match file {226 RawEntryMut::Occupied(ref mut d) => d.get_mut(),227 RawEntryMut::Vacant(v) => {228 let data = self.settings().import_resolver.load_file_contents(&path)?;229 v.insert(230 path.clone(),231 FileData::new_string(232 std::str::from_utf8(&data)233 .map_err(|_| ImportBadFileUtf8(path.clone()))?234 .into(),235 ),236 )237 .1238 }239 };240 Ok(file241 .get_string()242 .ok_or_else(|| ImportBadFileUtf8(path.clone()))?)243 }244 /// Should only be called with path retrieved from [`resolve_path`], may panic otherwise245 pub fn import_resolved_bin(&self, path: SourcePath) -> Result<IBytes> {246 let mut file_cache = self.file_cache();247 let mut file = file_cache.raw_entry_mut().from_key(&path);248249 let file = match file {250 RawEntryMut::Occupied(ref mut d) => d.get_mut(),251 RawEntryMut::Vacant(v) => {252 let data = self.settings().import_resolver.load_file_contents(&path)?;253 v.insert(path.clone(), FileData::new_bytes(data.as_slice().into()))254 .1255 }256 };257 if let Some(str) = &file.bytes {258 return Ok(str.clone());259 }260 if file.bytes.is_none() {261 file.bytes = Some(262 file.string263 .as_ref()264 .expect("either string or bytes should be set")265 .clone()266 .cast_bytes(),267 );268 }269 Ok(file.bytes.as_ref().expect("just set").clone())270 }271 /// Should only be called with path retrieved from [`resolve_path`], may panic otherwise272 pub fn import_resolved(&self, path: SourcePath) -> Result<Val> {273 let mut file_cache = self.file_cache();274 let mut file = file_cache.raw_entry_mut().from_key(&path);275276 let file = match file {277 RawEntryMut::Occupied(ref mut d) => d.get_mut(),278 RawEntryMut::Vacant(v) => {279 let data = self.settings().import_resolver.load_file_contents(&path)?;280 v.insert(281 path.clone(),282 FileData::new_string(283 std::str::from_utf8(&data)284 .map_err(|_| ImportBadFileUtf8(path.clone()))?285 .into(),286 ),287 )288 .1289 }290 };291 if let Some(val) = &file.evaluated {292 return Ok(val.clone());293 }294 let code = file295 .get_string()296 .ok_or_else(|| ImportBadFileUtf8(path.clone()))?;297 let file_name = Source::new(path.clone(), code.clone());298 if file.parsed.is_none() {299 file.parsed = Some(300 jrsonnet_parser::parse(301 &code,302 &ParserSettings {303 source: file_name.clone(),304 },305 )306 .map_err(|e| ImportSyntaxError {307 path: file_name.clone(),308 error: Box::new(e),309 })?,310 );311 }312 let parsed = file.parsed.as_ref().expect("just set").clone();313 if file.evaluating {314 throw!(InfiniteRecursionDetected)315 }316 file.evaluating = true;317 // Dropping file cache guard here, as evaluation may use this map too318 drop(file_cache);319 let res = evaluate(self.create_default_context(file_name), &parsed);320321 let mut file_cache = self.file_cache();322 let mut file = file_cache.raw_entry_mut().from_key(&path);323324 let RawEntryMut::Occupied(file) = &mut file else {325 unreachable!("this file was just here!")326 };327 let file = file.get_mut();328 file.evaluating = false;329 match res {330 Ok(v) => {331 file.evaluated = Some(v.clone());332 Ok(v)333 }334 Err(e) => Err(e),335 }336 }337338 /// Has same semantics as `import 'path'` called from `from` file339 pub fn import_from(&self, from: &SourcePath, path: &str) -> Result<Val> {340 let resolved = self.resolve_from(from, path)?;341 self.import_resolved(resolved)342 }343 pub fn import(&self, path: impl AsRef<Path>) -> Result<Val> {344 let resolved = self.resolve(path)?;345 self.import_resolved(resolved)346 }347348 /// Creates context with all passed global variables349 pub fn create_default_context(&self, source: Source) -> Context {350 let context_initializer = &self.settings().context_initializer;351 context_initializer.initialize(self.clone(), source)352 }353354 /// Executes code creating a new stack frame355 pub fn push<T>(356 e: CallLocation<'_>,357 frame_desc: impl FnOnce() -> String,358 f: impl FnOnce() -> Result<T>,359 ) -> Result<T> {360 let _guard = check_depth()?;361362 f().with_description_src(e, frame_desc)363 }364365 /// Executes code creating a new stack frame366 pub fn push_val(367 &self,368 e: &ExprLocation,369 frame_desc: impl FnOnce() -> String,370 f: impl FnOnce() -> Result<Val>,371 ) -> Result<Val> {372 let _guard = check_depth()?;373374 f().with_description_src(e, frame_desc)375 }376 /// Executes code creating a new stack frame377 pub fn push_description<T>(378 frame_desc: impl FnOnce() -> String,379 f: impl FnOnce() -> Result<T>,380 ) -> Result<T> {381 let _guard = check_depth()?;382383 f().with_description(frame_desc)384 }385}386387/// Internals388impl State {389 fn file_cache(&self) -> RefMut<'_, GcHashMap<SourcePath, FileData>> {390 self.0.file_cache.borrow_mut()391 }392 pub fn settings(&self) -> Ref<'_, EvaluationSettings> {393 self.0.settings.borrow()394 }395 pub fn settings_mut(&self) -> RefMut<'_, EvaluationSettings> {396 self.0.settings.borrow_mut()397 }398}399400/// Raw methods evaluate passed values but don't perform TLA execution401impl State {402 /// Parses and evaluates the given snippet403 pub fn evaluate_snippet(&self, name: impl Into<IStr>, code: impl Into<IStr>) -> Result<Val> {404 let code = code.into();405 let source = Source::new_virtual(name.into(), code.clone());406 let parsed = jrsonnet_parser::parse(407 &code,408 &ParserSettings {409 source: source.clone(),410 },411 )412 .map_err(|e| ImportSyntaxError {413 path: source.clone(),414 error: Box::new(e),415 })?;416 evaluate(self.create_default_context(source), &parsed)417 }418}419420/// Settings utilities421impl State {422 // Only panics in case of [`ImportResolver`] contract violation423 #[allow(clippy::missing_panics_doc)]424 pub fn resolve_from(&self, from: &SourcePath, path: &str) -> Result<SourcePath> {425 self.import_resolver().resolve_from(from, path.as_ref())426 }427428 // Only panics in case of [`ImportResolver`] contract violation429 #[allow(clippy::missing_panics_doc)]430 pub fn resolve(&self, path: impl AsRef<Path>) -> Result<SourcePath> {431 self.import_resolver().resolve(path.as_ref())432 }433 pub fn import_resolver(&self) -> Ref<'_, dyn ImportResolver> {434 Ref::map(self.settings(), |s| &*s.import_resolver)435 }436 pub fn set_import_resolver(&self, resolver: impl ImportResolver) {437 self.settings_mut().import_resolver = tb!(resolver);438 }439 pub fn context_initializer(&self) -> Ref<'_, dyn ContextInitializer> {440 Ref::map(self.settings(), |s| &*s.context_initializer)441 }442 pub fn set_context_initializer(&self, initializer: impl ContextInitializer) {443 self.settings_mut().context_initializer = tb!(initializer);444 }445}crates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -54,7 +54,7 @@
#[cfg(feature = "exp-preserve-order")]
mod ordering {
- use std::cmp::Reverse;
+ use std::cmp::{Ordering, Reverse};
use jrsonnet_gcmodule::Trace;
@@ -81,12 +81,10 @@
Self(Reverse(depth), index)
}
pub fn collide(self, other: Self) -> Self {
- if self.0 .0 > other.0 .0 {
- self
- } else if self.0 .0 < other.0 .0 {
- other
- } else {
- unreachable!("object can't have two fields with same name")
+ match self.0 .0.cmp(&other.0 .0) {
+ Ordering::Greater => self,
+ Ordering::Less => other,
+ Ordering::Equal => unreachable!("object can't have two fields with the same name"),
}
}
}
@@ -188,6 +186,12 @@
pub fn new_empty() -> Self {
Self::new(None, Cc::new(GcHashMap::new()), Cc::new(Vec::new()))
}
+ pub fn builder() -> ObjValueBuilder {
+ ObjValueBuilder::new()
+ }
+ pub fn builder_with_capacity(capacity: usize) -> ObjValueBuilder {
+ ObjValueBuilder::with_capacity(capacity)
+ }
#[must_use]
pub fn extend_from(&self, sup: Self) -> Self {
match &self.0.sup {
@@ -304,7 +308,7 @@
break;
}
fields[j] = fields[k].clone();
- j = k
+ j = k;
}
fields[j] = x;
}
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -33,6 +33,7 @@
Pending,
}
+/// Lazily evaluated value
#[allow(clippy::module_name_repetitions)]
#[derive(Clone, Trace)]
pub struct Thunk<T: Trace>(Cc<RefCell<ThunkInner<T>>>);
@@ -57,6 +58,13 @@
self.evaluate()?;
Ok(())
}
+
+ /// Evaluate thunk, or return cached value
+ ///
+ /// # Errors
+ ///
+ /// - Lazy value evaluation returned error
+ /// - This method was called during inner value evaluation
pub fn evaluate(&self) -> Result<T> {
match &*self.0.borrow() {
ThunkInner::Computed(v) => return Ok(v.clone()),
@@ -132,7 +140,7 @@
}
}
-/// Represents a Jsonnet value, which can be spliced or indexed (string or array).
+/// Represents a Jsonnet value, which can be sliced or indexed (string or array).
#[allow(clippy::module_name_repetitions)]
pub enum IndexableVal {
/// String.
@@ -247,6 +255,16 @@
}
}
}
+impl From<&str> for StrValue {
+ fn from(value: &str) -> Self {
+ Self::Flat(value.into())
+ }
+}
+impl From<String> for StrValue {
+ fn from(value: String) -> Self {
+ Self::Flat(value.into())
+ }
+}
impl Display for StrValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
crates/jrsonnet-parser/src/source.rsdiffbeforeafterboth--- a/crates/jrsonnet-parser/src/source.rs
+++ b/crates/jrsonnet-parser/src/source.rs
@@ -33,8 +33,8 @@
}
fn dyn_eq(&self, other: &dyn $T) -> bool {
let Some(other) = other.as_any().downcast_ref::<Self>() else {
- return false
- };
+ return false
+ };
let this = <Self as $T>::as_any(self)
.downcast_ref::<Self>()
.expect("restricted by impl");
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -211,7 +211,7 @@
locs[0].line
);
}
- eprintln!(" {}", value);
+ eprintln!(" {value}");
}
}
@@ -229,7 +229,7 @@
}
fn extvar_source(name: &str, code: impl Into<IStr>) -> Source {
- let source_name = format!("<extvar:{}>", name);
+ let source_name = format!("<extvar:{name}>");
Source::new_virtual(source_name.into(), code.into())
}
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -46,7 +46,7 @@
.ext_natives
.get(&x)
.cloned()
- .map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v.clone())))
+ .map_or(Val::Null, |v| Val::Func(FuncVal::Builtin(v)))
}
#[builtin(fields(
crates/jrsonnet-stdlib/src/parse.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/parse.rs
+++ b/crates/jrsonnet-stdlib/src/parse.rs
@@ -8,7 +8,7 @@
#[builtin]
pub fn builtin_parse_json(str: IStr) -> Result<Val> {
let value: Val = serde_json::from_str(&str)
- .map_err(|e| RuntimeError(format!("failed to parse json: {}", e).into()))?;
+ .map_err(|e| RuntimeError(format!("failed to parse json: {e}").into()))?;
Ok(value)
}
@@ -22,7 +22,7 @@
let mut out = vec![];
for item in value {
let val = Val::deserialize(item)
- .map_err(|e| RuntimeError(format!("failed to parse yaml: {}", e).into()))?;
+ .map_err(|e| RuntimeError(format!("failed to parse yaml: {e}").into()))?;
out.push(val);
}
Ok(if out.is_empty() {
crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-types/src/lib.rs
+++ b/crates/jrsonnet-types/src/lib.rs
@@ -150,7 +150,7 @@
if should_add_braces {
write!(f, "(")?;
}
- write!(f, "{}", v)?;
+ write!(f, "{v}")?;
if should_add_braces {
write!(f, ")")?;
}
@@ -162,7 +162,7 @@
if *a == ComplexValType::Any {
write!(f, "array")?
} else {
- write!(f, "Array<{}>", a)?
+ write!(f, "Array<{a}>")?
}
Ok(())
}
@@ -171,7 +171,7 @@
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ComplexValType::Any => write!(f, "any")?,
- ComplexValType::Simple(s) => write!(f, "{}", s)?,
+ ComplexValType::Simple(s) => write!(f, "{s}")?,
ComplexValType::Char => write!(f, "char")?,
ComplexValType::BoundedNumber(a, b) => write!(
f,
@@ -187,7 +187,7 @@
if i != 0 {
write!(f, ", ")?;
}
- write!(f, "{}: {}", k, v)?;
+ write!(f, "{k}: {v}")?;
}
write!(f, "}}")?;
}