-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minimal replacment. needs nested tables implementation
- Loading branch information
1 parent
91231b0
commit db5062b
Showing
4 changed files
with
127 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
|
||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub enum CallItem { | ||
Item( Box<str>, Option< Box<CallItem> > ), | ||
} | ||
impl CallItem { | ||
pub fn new( s: &str ) -> Self { | ||
Self::Item( s.into(), None ) | ||
} | ||
pub fn append(&self, s2: &str) -> Self { | ||
match &self { | ||
Self::Item( a, None ) => { | ||
Self::Item( | ||
a.clone(), | ||
Some( Self::new( &s2 ).into() ) | ||
) | ||
}, | ||
Self::Item( a, Some(b) ) => { | ||
let new_b = b.append(s2); | ||
Self::Item( | ||
a.clone(), | ||
Some( new_b.into() ) | ||
) | ||
}, | ||
} | ||
} | ||
} | ||
|
||
// // // // // // // // | ||
// TESTs | ||
// // // // // // // // | ||
|
||
#[test] | ||
fn NestedItems() { | ||
let t = CallItem | ||
::new( "a" ) | ||
.append( "b" ) | ||
.append( "c" ) | ||
.append( "d" ); | ||
pr( 0, &t ); | ||
} | ||
|
||
fn pr( n: i32, item: &CallItem ) { | ||
match item { | ||
CallItem::Item( a, None ) => { | ||
println!( "{} --> ({}, None)", n, a ); | ||
} | ||
CallItem::Item( a, Some(b) ) => { | ||
println!( "{} --> ({}, -- )", n, a ); | ||
pr( n+1, &b ); | ||
} | ||
} | ||
} | ||
|