@@ -33,6 +33,7 @@ use database::{Commit, Crate, Index, Lookup, ProcessStatistic, QueryLabel};
33
33
use std:: convert:: TryInto ;
34
34
use std:: fmt;
35
35
use std:: ops:: RangeInclusive ;
36
+ use std:: str:: FromStr ;
36
37
use std:: sync:: Arc ;
37
38
38
39
/// Finds the most appropriate `ArtifactId` for a given bound.
@@ -361,6 +362,17 @@ impl Query {
361
362
}
362
363
}
363
364
365
+ fn extract_as < T > ( & mut self , tag : Tag ) -> Result < Selector < T > , String >
366
+ where
367
+ T : FromStr ,
368
+ <T as FromStr >:: Err : fmt:: Display ,
369
+ {
370
+ Ok ( self . extract ( tag) ?. raw . try_map ( |p| {
371
+ p. parse :: < T > ( )
372
+ . map_err ( |e| format ! ( "failed to parse query tag {:?}: {}" , tag, e) )
373
+ } ) ?)
374
+ }
375
+
364
376
fn assert_empty ( & self ) -> Result < ( ) , String > {
365
377
if self . path . is_empty ( ) {
366
378
Ok ( ( ) )
@@ -528,11 +540,6 @@ impl SiteCtxt {
528
540
}
529
541
}
530
542
531
- #[ derive( Clone ) ]
532
- pub struct Source < ' a > {
533
- ctxt : & ' a SiteCtxt ,
534
- }
535
-
536
543
pub struct ProcessStatisticSeries {
537
544
artifact_ids : ArtifactIdIter ,
538
545
points : std:: vec:: IntoIter < Option < f64 > > ,
@@ -549,19 +556,10 @@ impl ProcessStatisticSeries {
549
556
mut query : Query ,
550
557
) -> Result < Vec < SeriesResponse < Self > > , String > {
551
558
let dumped = format ! ( "{:?}" , query) ;
552
- let krate = query. extract ( Tag :: Crate ) ?. raw ;
553
- let profile = query
554
- . extract ( Tag :: Profile ) ?
555
- . raw
556
- . try_map ( |p| p. parse :: < Profile > ( ) ) ?;
557
- let cache = query
558
- . extract ( Tag :: Cache ) ?
559
- . raw
560
- . try_map ( |p| p. parse :: < Cache > ( ) ) ?;
561
- let statid = query
562
- . extract ( Tag :: ProcessStatistic ) ?
563
- . raw
564
- . try_map ( |p| p. parse :: < ProcessStatistic > ( ) ) ?;
559
+ let krate = query. extract_as :: < String > ( Tag :: Crate ) ?;
560
+ let profile = query. extract_as :: < Profile > ( Tag :: Profile ) ?;
561
+ let cache = query. extract_as :: < Cache > ( Tag :: Cache ) ?;
562
+ let statid = query. extract_as :: < ProcessStatistic > ( Tag :: ProcessStatistic ) ?;
565
563
query. assert_empty ( ) ?;
566
564
567
565
let index = ctxt. index . load ( ) ;
@@ -736,15 +734,9 @@ impl SelfProfile {
736
734
ctxt : & SiteCtxt ,
737
735
mut query : Query ,
738
736
) -> Result < Vec < SeriesResponse < Self > > , String > {
739
- let krate = query. extract ( Tag :: Crate ) ?. raw ;
740
- let profile = query
741
- . extract ( Tag :: Profile ) ?
742
- . raw
743
- . try_map ( |p| p. parse :: < Profile > ( ) ) ?;
744
- let cache = query
745
- . extract ( Tag :: Cache ) ?
746
- . raw
747
- . try_map ( |p| p. parse :: < Cache > ( ) ) ?;
737
+ let krate = query. extract_as :: < String > ( Tag :: Crate ) ?;
738
+ let profile = query. extract_as :: < Profile > ( Tag :: Profile ) ?;
739
+ let cache = query. extract_as :: < Cache > ( Tag :: Cache ) ?;
748
740
query. assert_empty ( ) ?;
749
741
750
742
let mut series = ctxt
@@ -832,19 +824,10 @@ impl SelfProfileQueryTime {
832
824
ctxt : & SiteCtxt ,
833
825
mut query : Query ,
834
826
) -> Result < Vec < SeriesResponse < Self > > , String > {
835
- let krate = query. extract ( Tag :: Crate ) ?. raw ;
836
- let profile = query
837
- . extract ( Tag :: Profile ) ?
838
- . raw
839
- . try_map ( |p| p. parse :: < Profile > ( ) ) ?;
840
- let cache = query
841
- . extract ( Tag :: Cache ) ?
842
- . raw
843
- . try_map ( |p| p. parse :: < Cache > ( ) ) ?;
844
- let ql = query
845
- . extract ( Tag :: QueryLabel ) ?
846
- . raw
847
- . map ( |p| QueryLabel :: from ( p. as_str ( ) ) ) ;
827
+ let krate = query. extract_as :: < String > ( Tag :: Crate ) ?;
828
+ let profile = query. extract_as :: < Profile > ( Tag :: Profile ) ?;
829
+ let cache = query. extract_as :: < Cache > ( Tag :: Cache ) ?;
830
+ let ql = query. extract_as :: < QueryLabel > ( Tag :: QueryLabel ) ?;
848
831
query. assert_empty ( ) ?;
849
832
850
833
let index = ctxt. index . load ( ) ;
0 commit comments