1- use super :: { AsRangedCoord , DiscreteRanged , Ranged } ;
2- use std:: fmt:: { Debug , Formatter , Result as FmtResult } ;
1+ use super :: { AsRangedCoord , DiscreteRanged , Ranged , ValueFormatter } ;
32use std:: ops:: Range ;
43
54/// Describe a value for a nested croodinate
6- #[ derive( PartialEq , Eq , Clone ) ]
5+ #[ derive( PartialEq , Eq , Clone , Debug ) ]
76pub enum NestedValue < C , V > {
87 /// Category value
98 Category ( C ) ,
@@ -40,15 +39,6 @@ impl<C, V> From<C> for NestedValue<C, V> {
4039 }
4140}
4241
43- impl < C : Debug , V : Debug > Debug for NestedValue < C , V > {
44- fn fmt ( & self , formatter : & mut Formatter ) -> FmtResult {
45- match self {
46- NestedValue :: Category ( cat) => write ! ( formatter, "{:?}" , cat) ,
47- NestedValue :: Value ( _, val) => write ! ( formatter, "{:?}" , val) ,
48- }
49- }
50- }
51-
5242/// A nested coordinate spec which is a discrete coordinate on the top level and
5343/// for each value in discrete value, there is a secondary coordinate system.
5444/// And the value is defined as a tuple of primary coordinate value and secondary
@@ -58,8 +48,23 @@ pub struct NestedRange<Primary: DiscreteRanged, Secondary: Ranged> {
5848 secondary : Vec < Secondary > ,
5949}
6050
51+ impl < PT , ST , P , S > ValueFormatter < NestedValue < PT , ST > > for NestedRange < P , S >
52+ where
53+ P : Ranged < ValueType = PT > + DiscreteRanged ,
54+ S : Ranged < ValueType = ST > ,
55+ P : ValueFormatter < PT > ,
56+ S : ValueFormatter < ST > ,
57+ {
58+ fn format ( value : & NestedValue < PT , ST > ) -> String {
59+ match value {
60+ NestedValue :: Category ( cat) => P :: format ( cat) ,
61+ NestedValue :: Value ( _, val) => S :: format ( val) ,
62+ }
63+ }
64+ }
65+
6166impl < P : DiscreteRanged , S : Ranged > Ranged for NestedRange < P , S > {
62- type FormatOption = crate :: coord:: ranged:: DefaultFormatting ;
67+ type FormatOption = crate :: coord:: ranged:: NoDefaultFormatting ;
6368 type ValueType = NestedValue < P :: ValueType , S :: ValueType > ;
6469
6570 fn range ( & self ) -> Range < Self :: ValueType > {
0 commit comments