33//! Using this module, you can define Nickel records using a builder style. For example:
44//!
55//! ```rust
6- //! # use nickel_lang_core::term::{MergePriority, Term, RichTerm , make::builder::Record};
6+ //! # use nickel_lang_core::term::{MergePriority, Term, NickelValue , make::builder::Record};
77//! let b = Record::new()
88//! .field("foo")
99//! .priority(MergePriority::Bottom)
1010//! .doc("foo?")
1111//! .not_exported()
1212//! .value(Term::Str("foo".into()));
13- //! let t : RichTerm = b
13+ //! let t : NickelValue = b
1414//! .field("bar")
1515//! .value(Term::Num(42.into()))
1616//! .into();
1919use indexmap:: IndexMap ;
2020
2121use crate :: {
22+ bytecode:: value:: NickelValue ,
2223 combine:: Combine ,
2324 identifier:: { Ident , LocIdent } ,
2425 label:: Label ,
2526 term:: {
2627 make:: op2,
2728 record:: { self , FieldMetadata , RecordAttrs , RecordData } ,
28- BinaryOp , LabeledType , MergePriority , RichTerm , Term ,
29+ BinaryOp , LabeledType , MergePriority ,
2930 } ,
3031 typ:: Type ,
3132} ;
@@ -36,7 +37,7 @@ type StaticPath = Vec<Ident>;
3637pub struct Incomplete ( ) ;
3738
3839/// Typestate style tag for `Field`s that have been finalized
39- pub struct Complete ( Option < RichTerm > ) ;
40+ pub struct Complete ( Option < NickelValue > ) ;
4041
4142/// A Nickel record field being constructed
4243#[ derive( Debug ) ]
@@ -155,7 +156,7 @@ impl Field<Incomplete> {
155156 }
156157
157158 /// Finalize the [`Field`] by setting its value
158- pub fn value ( self , value : impl Into < RichTerm > ) -> Field < Complete > {
159+ pub fn value ( self , value : impl Into < NickelValue > ) -> Field < Complete > {
159160 Field {
160161 record : Complete ( Some ( value. into ( ) ) ) ,
161162 path : self . path ,
@@ -194,7 +195,7 @@ impl Field<Record> {
194195 }
195196
196197 /// Finalize the [`Field`] by setting its a value
197- pub fn value ( mut self , value : impl Into < RichTerm > ) -> Record {
198+ pub fn value ( mut self , value : impl Into < NickelValue > ) -> Record {
198199 self . record . fields . push ( (
199200 self . path ,
200201 record:: Field {
@@ -223,16 +224,16 @@ where
223224 let fst = it. next ( ) . unwrap ( ) ;
224225
225226 let content = it. rev ( ) . fold ( content, |acc, id| {
226- record:: Field :: from ( RichTerm :: from ( Term :: Record ( RecordData {
227+ record:: Field :: from ( NickelValue :: record_posless ( RecordData {
227228 fields : [ ( LocIdent :: from ( id) , acc) ] . into ( ) ,
228229 ..Default :: default ( )
229- } ) ) )
230+ } ) )
230231 } ) ;
231232
232233 ( fst. into ( ) , content)
233234}
234235
235- fn build_record < I > ( fields : I , attrs : RecordAttrs ) -> Term
236+ fn build_record < I > ( fields : I , attrs : RecordAttrs ) -> NickelValue
236237where
237238 I : IntoIterator < Item = ( LocIdent , record:: Field ) > ,
238239{
@@ -262,7 +263,8 @@ where
262263 }
263264 }
264265 }
265- Term :: Record ( RecordData :: new ( static_fields, attrs, None ) )
266+
267+ NickelValue :: record_posless ( RecordData :: new ( static_fields, attrs, None ) )
266268}
267269
268270impl Record {
@@ -336,13 +338,13 @@ impl Record {
336338 self
337339 }
338340
339- /// Finalize the record and turn it into a [`crate::term::RichTerm `]
340- pub fn build ( self ) -> RichTerm {
341+ /// Finalize the record and turn it into a [`crate::term::NickelValue `]
342+ pub fn build ( self ) -> NickelValue {
341343 let elaborated = self
342344 . fields
343345 . into_iter ( )
344346 . map ( |( path, rt) | elaborate_field_path ( path, rt) ) ;
345- build_record ( elaborated, self . attrs ) . into ( )
347+ build_record ( elaborated, self . attrs )
346348 }
347349}
348350
@@ -362,7 +364,7 @@ where
362364 }
363365}
364366
365- impl From < Record > for RichTerm {
367+ impl From < Record > for NickelValue {
366368 fn from ( val : Record ) -> Self {
367369 val. build ( )
368370 }
@@ -372,7 +374,7 @@ impl From<Record> for RichTerm {
372374mod tests {
373375 use crate :: {
374376 position:: TermPos ,
375- term:: { RichTerm , TypeAnnotation } ,
377+ term:: { NickelValue , TypeAnnotation } ,
376378 typ:: { Type , TypeF } ,
377379 } ;
378380
@@ -381,12 +383,12 @@ mod tests {
381383 use super :: * ;
382384
383385 fn term ( t : Term ) -> record:: Field {
384- record:: Field :: from ( RichTerm :: from ( t) )
386+ record:: Field :: from ( NickelValue :: from ( t) )
385387 }
386388
387389 #[ test]
388390 fn trivial ( ) {
389- let t: RichTerm = Record :: new ( )
391+ let t: NickelValue = Record :: new ( )
390392 . field ( "foo" )
391393 . value ( Term :: Str ( "bar" . into ( ) ) )
392394 . into ( ) ;
@@ -402,7 +404,7 @@ mod tests {
402404
403405 #[ test]
404406 fn from_iter ( ) {
405- let t: RichTerm = Record :: from ( [
407+ let t: NickelValue = Record :: from ( [
406408 Field :: name ( "foo" ) . value ( Term :: Null ) ,
407409 Field :: name ( "bar" ) . value ( Term :: Null ) ,
408410 ] )
@@ -422,7 +424,7 @@ mod tests {
422424
423425 #[ test]
424426 fn some_doc ( ) {
425- let t: RichTerm = Record :: from ( [
427+ let t: NickelValue = Record :: from ( [
426428 Field :: name ( "foo" ) . some_doc ( Some ( "foo" ) ) . no_value ( ) ,
427429 Field :: name ( "bar" ) . some_doc ( None as Option < & str > ) . no_value ( ) ,
428430 Field :: name ( "baz" ) . doc ( "baz" ) . no_value ( ) ,
@@ -456,7 +458,7 @@ mod tests {
456458
457459 #[ test]
458460 fn fields ( ) {
459- let t: RichTerm = Record :: new ( )
461+ let t: NickelValue = Record :: new ( )
460462 . fields ( [
461463 Field :: name ( "foo" ) . value ( Term :: Str ( "foo" . into ( ) ) ) ,
462464 Field :: name ( "bar" ) . value ( Term :: Str ( "bar" . into ( ) ) ) ,
@@ -477,7 +479,7 @@ mod tests {
477479
478480 #[ test]
479481 fn fields_metadata ( ) {
480- let t: RichTerm = Record :: new ( )
482+ let t: NickelValue = Record :: new ( )
481483 . fields ( [
482484 Field :: name ( "foo" ) . optional ( ) . no_value ( ) ,
483485 Field :: name ( "bar" ) . optional ( ) . no_value ( ) ,
@@ -510,7 +512,7 @@ mod tests {
510512
511513 #[ test]
512514 fn overriding ( ) {
513- let t: RichTerm = Record :: new ( )
515+ let t: NickelValue = Record :: new ( )
514516 . path ( vec ! [ "terraform" , "required_providers" ] )
515517 . value ( Record :: from ( [
516518 Field :: name ( "foo" ) . value ( Term :: Null ) ,
@@ -551,7 +553,7 @@ mod tests {
551553
552554 #[ test]
553555 fn open_record ( ) {
554- let t: RichTerm = Record :: new ( ) . open ( ) . into ( ) ;
556+ let t: NickelValue = Record :: new ( ) . open ( ) . into ( ) ;
555557 assert_eq ! (
556558 t,
557559 build_record(
@@ -567,7 +569,7 @@ mod tests {
567569
568570 #[ test]
569571 fn prio_metadata ( ) {
570- let t: RichTerm = Record :: new ( )
572+ let t: NickelValue = Record :: new ( )
571573 . field ( "foo" )
572574 . priority ( MergePriority :: Top )
573575 . no_value ( )
@@ -590,7 +592,7 @@ mod tests {
590592
591593 #[ test]
592594 fn contract ( ) {
593- let t: RichTerm = Record :: new ( )
595+ let t: NickelValue = Record :: new ( )
594596 . field ( "foo" )
595597 . contract ( TypeF :: String )
596598 . no_value ( )
@@ -619,7 +621,7 @@ mod tests {
619621
620622 #[ test]
621623 fn exercise_metadata ( ) {
622- let t: RichTerm = Record :: new ( )
624+ let t: NickelValue = Record :: new ( )
623625 . field ( "foo" )
624626 . priority ( MergePriority :: Bottom )
625627 . doc ( "foo?" )
0 commit comments