@@ -117,48 +117,29 @@ pub trait TemplateContext: Serialize {
117117
118118#[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord ) ]
119119pub struct SampleIdentifier {
120- /// A stable locale identifier.
121- pub locale : Option < String > ,
122-
123- /// A stable identifier for the session that was used in this sample.
124- pub session_index : Option < usize > ,
125-
126- /// A stable positional index of the sample for this context.
127- pub index : usize ,
120+ pub components : Vec < ( & ' static str , String ) > ,
128121}
129122
130123impl SampleIdentifier {
131- pub fn with_locale ( & self , locale : String ) -> Self {
132- SampleIdentifier {
133- locale : Some ( locale) ,
134- session_index : self . session_index ,
135- index : self . index ,
124+ pub fn from_index ( index : usize ) -> Self {
125+ Self {
126+ components : Vec :: default ( ) ,
136127 }
128+ . with_appended ( "index" , format ! ( "{index}" ) )
137129 }
138130
139- pub fn with_session_index ( self , session_index : usize ) -> Self {
140- SampleIdentifier {
141- locale : self . locale ,
142- session_index : Some ( session_index) ,
143- index : self . index ,
144- }
131+ pub fn with_appended ( & self , kind : & ' static str , locale : String ) -> Self {
132+ let mut new = self . clone ( ) ;
133+ new. components . push ( ( kind, locale) ) ;
134+ new
145135 }
146136}
147137
148138pub ( crate ) fn sample_list < T : TemplateContext > ( samples : Vec < T > ) -> BTreeMap < SampleIdentifier , T > {
149139 samples
150140 . into_iter ( )
151141 . enumerate ( )
152- . map ( |( index, sample) | {
153- (
154- SampleIdentifier {
155- locale : None ,
156- session_index : None ,
157- index,
158- } ,
159- sample,
160- )
161- } )
142+ . map ( |( index, sample) | ( SampleIdentifier :: from_index ( index) , sample) )
162143 . collect ( )
163144}
164145
@@ -215,7 +196,7 @@ impl<T: TemplateContext> TemplateContext for WithLanguage<T> {
215196 . into_iter ( )
216197 . map ( |( sample_id, sample) | {
217198 (
218- sample_id. with_locale ( locale. to_string ( ) ) ,
199+ sample_id. with_appended ( "locale" , locale. to_string ( ) ) ,
219200 WithLanguage {
220201 lang : locale. to_string ( ) ,
221202 inner : sample,
@@ -286,7 +267,7 @@ impl<T: TemplateContext> TemplateContext for WithSession<T> {
286267 . into_iter ( )
287268 . map ( move |( k, inner) | {
288269 (
289- k. with_session_index ( session_index) ,
270+ k. with_appended ( "browser-session" , session_index. to_string ( ) ) ,
290271 WithSession {
291272 current_session : session. clone ( ) ,
292273 inner,
@@ -327,7 +308,7 @@ impl<T: TemplateContext> TemplateContext for WithOptionalSession<T> {
327308 . map ( move |( k, inner) | {
328309 (
329310 if session. is_some ( ) {
330- k. with_session_index ( session_index)
311+ k. with_appended ( "browser-session" , session_index. to_string ( ) )
331312 } else {
332313 k
333314 } ,
0 commit comments