|
15 | 15 | "use strict";
|
16 | 16 | varresizeTimeout,interval;
|
17 | 17 |
|
| 18 | +// This mapping table should match the discriminants of |
| 19 | +// `rustdoc::html::item_type::ItemType` type in Rust. |
| 20 | +varitemTypes=["mod", |
| 21 | +"externcrate", |
| 22 | +"import", |
| 23 | +"struct", |
| 24 | +"enum", |
| 25 | +"fn", |
| 26 | +"type", |
| 27 | +"static", |
| 28 | +"trait", |
| 29 | +"impl", |
| 30 | +"tymethod", |
| 31 | +"method", |
| 32 | +"structfield", |
| 33 | +"variant", |
| 34 | +"macro", |
| 35 | +"primitive", |
| 36 | +"associatedtype", |
| 37 | +"constant"]; |
| 38 | + |
18 | 39 | $('.js-only').removeClass('js-only');
|
19 | 40 |
|
20 | 41 | functiongetQueryStringParams(){
|
|
33 | 54 | returnwindow.history&&typeofwindow.history.pushState==="function";
|
34 | 55 | }
|
35 | 56 |
|
36 |
| -functionresizeShortBlocks(){ |
37 |
| -if(resizeTimeout){ |
38 |
| -clearTimeout(resizeTimeout); |
39 |
| -} |
40 |
| -resizeTimeout=setTimeout(function(){ |
41 |
| -varcontentWidth=$('.content').width(); |
42 |
| -$('.docblock.short').width(function(){ |
43 |
| -returncontentWidth-40-$(this).prev().width(); |
44 |
| -}).addClass('nowrap'); |
45 |
| -$('.summary-column').width(function(){ |
46 |
| -returncontentWidth-40-$(this).prev().width(); |
47 |
| -}) |
48 |
| -},150); |
49 |
| -} |
50 |
| -resizeShortBlocks(); |
51 |
| -$(window).on('resize',resizeShortBlocks); |
52 |
| - |
53 | 57 | functionhighlightSourceLines(ev){
|
54 | 58 | vari,from,to,match=window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
|
55 | 59 | if(match){
|
|
205 | 209 | break;
|
206 | 210 | }
|
207 | 211 | }
|
| 212 | +// searching by type |
| 213 | +}elseif(val.search("->")>-1){ |
| 214 | +vartrimmer=function(s){returns.trim();}; |
| 215 | +varparts=val.split("->").map(trimmer); |
| 216 | +varinput=parts[0]; |
| 217 | +// sort inputs so that order does not matter |
| 218 | +varinputs=input.split(",").map(trimmer).sort(); |
| 219 | +varoutput=parts[1]; |
| 220 | + |
| 221 | +for(vari=0;i<nSearchWords;++i){ |
| 222 | +vartype=searchIndex[i].type; |
| 223 | +if(!type){ |
| 224 | +continue; |
| 225 | +} |
| 226 | + |
| 227 | +// sort index inputs so that order does not matter |
| 228 | +vartypeInputs=type.inputs.map(function(input){ |
| 229 | +returninput.name; |
| 230 | +}).sort(); |
| 231 | + |
| 232 | +// allow searching for void (no output) functions as well |
| 233 | +vartypeOutput=type.output ?type.output.name :""; |
| 234 | +if(inputs.toString()===typeInputs.toString()&& |
| 235 | +output==typeOutput){ |
| 236 | +results.push({id:i,index:-1,dontValidate:true}); |
| 237 | +} |
| 238 | +} |
208 | 239 | }else{
|
209 | 240 | // gather matching search results up to a certain maximum
|
210 | 241 | val=val.replace(/\_/g,"");
|
|
325 | 356 | path=result.item.path.toLowerCase(),
|
326 | 357 | parent=result.item.parent;
|
327 | 358 |
|
| 359 | +// this validation does not make sense when searching by types |
| 360 | +if(result.dontValidate){ |
| 361 | +continue; |
| 362 | +} |
| 363 | + |
328 | 364 | varvalid=validateResult(name,path,split,parent);
|
329 | 365 | if(!valid){
|
330 | 366 | result.id=-1;
|
|
552 | 588 | showResults(results);
|
553 | 589 | }
|
554 | 590 |
|
555 |
| -// This mapping table should match the discriminants of |
556 |
| -// `rustdoc::html::item_type::ItemType` type in Rust. |
557 |
| -varitemTypes=["mod", |
558 |
| -"externcrate", |
559 |
| -"import", |
560 |
| -"struct", |
561 |
| -"enum", |
562 |
| -"fn", |
563 |
| -"type", |
564 |
| -"static", |
565 |
| -"trait", |
566 |
| -"impl", |
567 |
| -"tymethod", |
568 |
| -"method", |
569 |
| -"structfield", |
570 |
| -"variant", |
571 |
| -"macro", |
572 |
| -"primitive", |
573 |
| -"associatedtype", |
574 |
| -"constant"]; |
575 |
| - |
576 | 591 | functionitemTypeFromName(typename){
|
577 | 592 | for(vari=0;i<itemTypes.length;++i){
|
578 | 593 | if(itemTypes[i]===typename)returni;
|
|
590 | 605 | // (String) name,
|
591 | 606 | // (String) full path or empty string for previous path,
|
592 | 607 | // (String) description,
|
593 |
| -// (optional Number) the parent path index to `paths`] |
| 608 | +// (Number | null) the parent path index to `paths`] |
| 609 | +// (Object | null) the type of the function (if any) |
594 | 610 | varitems=rawSearchIndex[crate].items;
|
595 | 611 | // an array of [(Number) item type,
|
596 | 612 | // (String) name]
|
|
615 | 631 | varrawRow=items[i];
|
616 | 632 | varrow={crate:crate,ty:rawRow[0],name:rawRow[1],
|
617 | 633 | path:rawRow[2]||lastPath,desc:rawRow[3],
|
618 |
| -parent:paths[rawRow[4]]}; |
| 634 | +parent:paths[rawRow[4]],type:rawRow[5]}; |
619 | 635 | searchIndex.push(row);
|
620 | 636 | if(typeofrow.name==="string"){
|
621 | 637 | varword=row.name.toLowerCase();
|
|
708 | 724 |
|
709 | 725 | window.initSearch=initSearch;
|
710 | 726 |
|
| 727 | +// delayed sidebar rendering. |
| 728 | +functioninitSidebarItems(items){ |
| 729 | +varsidebar=$('.sidebar'); |
| 730 | +varcurrent=window.sidebarCurrent; |
| 731 | + |
| 732 | +functionblock(shortty,longty){ |
| 733 | +varfiltered=items[shortty]; |
| 734 | +if(!filtered)return; |
| 735 | + |
| 736 | +vardiv=$('<div>').attr('class','block '+shortty); |
| 737 | +div.append($('<h2>').text(longty)); |
| 738 | + |
| 739 | +for(vari=0;i<filtered.length;++i){ |
| 740 | +varitem=filtered[i]; |
| 741 | +varname=item[0]; |
| 742 | +vardesc=item[1];// can be null |
| 743 | + |
| 744 | +varklass=shortty; |
| 745 | +if(name===current.name&&shortty==current.ty){ |
| 746 | +klass+=' current'; |
| 747 | +} |
| 748 | +varpath; |
| 749 | +if(shortty==='mod'){ |
| 750 | +path=name+'/index.html'; |
| 751 | +}else{ |
| 752 | +path=shortty+'.'+name+'.html'; |
| 753 | +} |
| 754 | +div.append($('<a>',{'href':current.relpath+path, |
| 755 | +'title':desc, |
| 756 | +'class':klass}).text(name)); |
| 757 | +} |
| 758 | +sidebar.append(div); |
| 759 | +} |
| 760 | + |
| 761 | +block("mod","Modules"); |
| 762 | +block("struct","Structs"); |
| 763 | +block("enum","Enums"); |
| 764 | +block("trait","Traits"); |
| 765 | +block("fn","Functions"); |
| 766 | +block("macro","Macros"); |
| 767 | +} |
| 768 | + |
| 769 | +window.initSidebarItems=initSidebarItems; |
| 770 | + |
711 | 771 | window.register_implementors=function(imp){
|
712 | 772 | varlist=$('#implementors-list');
|
713 | 773 | varlibs=Object.getOwnPropertyNames(imp);
|
|