-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.html
executable file
·1057 lines (999 loc) · 42.2 KB
/
new.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css" />
<!--<link rel="stylesheet" type="text/css" href="original.css" />-->
<meta charset="utf-8" />
<!-- meta http-equiv="refresh" content="3" -->
</head>
<body>
<!-- Load saved parameters that can alter the layout before the element to layout -->
<script type="text/javascript">
var slider_position = localStorage.getItem("slider");
if (slider_position != null) {
document.body.style.setProperty("--sidebar-width", slider_position + "px");
}
var group_mode = localStorage.getItem("summary-group");
if (group_mode == "fn") {
document.body.style.setProperty("--group-impl", "none");
document.body.style.setProperty("--group-fn", "unset");
}
else {
group_mode="impl"
document.body.style.setProperty("--group-impl", "unset");
document.body.style.setProperty("--group-fn", "none");
}
var sort_mode = localStorage.getItem("summary-sort");
if (sort_mode == "sort") {
document.body.style.setProperty("--sort", "unset");
document.body.style.setProperty("--nosort", "none");
}
else {
sort_mode="nosort";
document.body.style.setProperty("--sort", "none");
document.body.style.setProperty("--nosort", "unset");
}
var blanket_mode = localStorage.getItem("summary-sort");
if (blanket_mode == "visible") {
document.body.style.setProperty("--blanket", "unset");
document.body.style.setProperty("--noblanket", "none");
}
else {
blanket_mode="hidden";
document.body.style.setProperty("--blanket", "none");
document.body.style.setProperty("--noblanket", "unset");
}
</script>
<!-- The invisible item that will contain the original documentation page -->
<section id="source" style="display: none">
</section>
<!-- The box used to dispay advanced tooltips -->
<nav id="infobox" class="infobox">
Tooltip text.
</nav>
<!-- The resizable sidebar -->
<nav class="sidebar" id="sidebar">
<div id="crateinfo" class="crateinfo">
<img class="logo" src="img/logo.png" /><br>
Rust standard library
</div>
<hr>
<div class="searchbox">
Search: <br>
<input />
</div>
<hr>
<div id="cratetree" class="cratetree">
<ul>
<li id="book_root" data-path="book" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/book.png" />
<a href="book/index.png" onclick="set_page('book/index.html');return false">The Book</a>
</li>
<li id="keywords_root" data-path="std" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/primitive.png" />
<a href="std/index.html" onclick="set_page('std/keywords.html');return false">Keywords</a>
</li>
<li id="primitives_root" data-path="std" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/primitive.png" />
<a href="std/index.html" onclick="set_page('std/primitives.html');return false">Primitives</a>
</li>
<li id="alloc_root" data-path="alloc" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/crate.png" />
<a href="alloc/index.html" onclick="set_page('alloc/index.html');return false">alloc</a>
</li>
<li id="core_root" data-path="core" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/crate.png" />
<a href="core/index.html" onclick="set_page('core/index.html');return false">core</a>
</li>
<li id="proc_macro_root" data-path="proc_macro" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/crate.png" />
<a href="proc_macro/index.html" onclick="set_page('proc_macro/index.html');return false">proc_macro</a>
</li>
<li id="std_root" data-path="std" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/crate.png" />
<a href="std/index.html" onclick="set_page('std/index.html');return false">std</a>
</li>
<li id="test_root" data-path="test" class="can_fold l1">
<img src="img/arrow/fold.png" />
<img src="img/item/crate.png" />
<a href="test/index.html" onclick="set_page('test/index.html');return false">test</a>
</li>
</ul>
</div>
</nav>
<!-- The invisible slider used to resize the sidebar -->
<nav id="slider" class="slider">
</nav>
<!-- The right side of the page containing the informations -->
<section class="main">
<!-- The title area-->
<section class="title">
<span id="title_item" class="item"></span>
<span class="shortdesc"></span>
<span class="since">since<br><b>1.0.0</b></span>
</section>
<!-- The menu bar-->
<nav class="menubar">
<a href="#description">
<div class="section" id="menu_description">Description</div>
</a>
<a href="#summary">
<div class="section" id="menu_summary">Summary</div>
</a>
<a href="#methods">
<div class="section" id="menu_methods">Methods</div>
</a>
<div class="section empty"></div>
<nav class="descr_index" id="descr_index">
</nav>
<a href="#source">
<div class="section">Source</div>
</a>
</nav>
<!-- The scrollable content area -->
<section class="content">
<section id="description" class="description">
<h2>Description</h2>
</section>
<hr>
<section id="summary" class="summary">
<section id="item_section">
<h4>Items: </h4>
<table id="item_table">
</table>
<template id="item_row">
<tr>
<td class="icon"><img src="img/item/fn.png" /></td>
<td class="shortname"><a href="#"></a></td>
<td class="shortdesc"></td>
</tr>
</template>
</section>
<section id="declaration_section">
<h4>Declaration: </h4>
<pre id="declaration" class="summary fiedls_declaration"></pre>
</section>
<section id="implementation_section">
<h4 class="impl_type">Implementations:</h4>
<span id="impl_list" class="impl"></span>
</section>
<section id="method_section">
<h4>Methods:
<a class="summary_button" onclick="switch_group()" >
<img src="img/arrow/flat.png" title="Grouped by method name" style="display: var(--group-fn)" />
<img src="img/arrow/tree.png" title="Grouped by implementation" style="display: var(--group-impl)" />
</a>
<a class="summary_button" onclick="switch_sort()" >
<img src="img/arrow/sorted.png" title="Ordered by method name" style="display: var(--sort)" />
<img src="img/arrow/unsorted.png" title="Oredered as in the source code" style="display: var(--nosort)" />
</a>
<a class="summary_button" onclick="switch_blanket()" >
<img src="img/arrow/blanket5.png" title="Blanket implementations visible" style="display: var(--blanket)" />
<img src="img/arrow/blanket6.png" title="Blanket implementation hidden" style="display: var(--noblanket)" />
</a>
</h4>
<table id="method_table">
</table>
<template id="fn_row">
<tr>
<td class="folder"><img src="img/arrow/empty.png" /></td>
<td class="icon"><img src="img/item/fn.png" /></td>
<td class="shortname"><a href="#"></a></td>
<td class="shortimpl"></td>
<td class="shortdesc"></td>
<td class="fullname"></td>
<td class="fullimpl"></td>
</tr>
</template>
<template id="impl_row">
<tr class="full_impl can_fold open">
<td class="folder"><img src="img/arrow/open.png" /></td>
<td colspan="5"></td>
</tr>
</template>
</section>
</section>
<hr>
<section id="methods" class="methods">
</section>
</section>
</section>
<script type="text/javascript">
const img_fold = "img/arrow/fold.png";
const img_open = "img/arrow/open.png";
const img_empty = "img/arrow/empty.png";
const mappings={
book:{
order:0,
icon:"img/book.png",
expand:true,
link:"/$/index.html",
to:"book_root"
},
chapter:{
order:1,
icon:"img/book.png",
expand:true,
link:"/$/index.html",
to:"book_root"
},
page:{
order:1,
icon:"img/book.png",
expand:true,
link:"/$/index.html",
to:"book_root"
},
keyword:{
order:5,
icon:"img/item/page.png",
expand:false,
link:"/keyword.$.html",
to:"keywords_root"
},
primitive:{
order:6,
icon:"img/item/block.png",
expand:false,
link:"/primitive.$.html",
to:"primitives_root"
},
crate:{
order:10,
icon:"img/item/crate.png",
expand:true,
link:"/$/index.html"
},
mod:{
order:11,
icon:"img/item/mod.png",
expand:true,
link:"/$/index.html"
},
type:{
order:12,
icon:"img/item/type.png",
link:"/type.$.html",
expand:false
},
struct:{
order:13,
icon:"img/item/struct.png",
link:"/struct.$.html",
expand:false
},
constant:{
order:13,
icon:"img/item/const.png",
link:"/constant.$.html",
expand:false
},
enum:{
order:14,
icon:"img/item/enum.png",
link:"/enum.$.html",
expand:false
},
union:{
order:15,
icon:"img/item/union.png",
link:"/union.$.html",
expand:false
},
trait:{
order:16,
icon:"img/item/trait.png",
link:"/trait.$.html",
expand:false
},
fn:{
order:17,
icon:"img/item/fn.png",
link:"/fn.$.html",
expand:false
},
macro:{
order:18,
icon:"img/item/macro.png",
link:"/macro.$.html",
expand:false
}
};
let content = document.querySelector(".content");
set_unfold_sidebar();
set_page("std/index.html");
// Set the sidebar eady for the current page
function sidebar_current(url){
let path_elt = url.split("/");
let path = ""
var elt;
for (var i=0; i+1<path_elt.length; i++){
let dir = path_elt[i];
path += dir;
if (i==0 && path=="std") {
if (url.includes("/keyword.")){
elt = document.getElementById("keywords_root")
}
else if (url.includes("/primitives.")){
elt = document.getElementById("keywords_root")
}
else {
elt = document.getElementById("std_root");
}
}
else {
elt = document.querySelector("li[data-path='"+path+"']")
}
if (elt.classList.contains("can_fold")){
elt.classList.add("open");
elt.firstElementChild.src=img_open;
}
let next = elt.nextElementSibling
if (next && next.tagName!="UL"){
load_node(elt);
}
path += "/";
}
let last=path_elt[path_elt.length-1];
if (last!="index.html"){
path += last.replace(/.*\.(.+?)\.html/,"$1");
elt = document.querySelector("li[data-path='"+path+"']")
}
old_elt = document.querySelector(".selected");
if (old_elt) {old_elt.classList.remove("selected")}
elt.classList.add("selected");
}
async function load_node(elt){
let path = elt.getAttribute("data-path");
if (path){
let response = await fetch(path+"/sidebar-items.js");
let text = await response.text();
text= text.replace(/^.*?\(/,"");
text= text.replace(/\);$/,"");
let items = JSON.parse(text);
let ul = document.createElement("ul");
var level=1;
for (cls of elt.classList){
if(cls.startsWith("l")){
level=parseInt(cls.substring(1),10)+1;
}
}
var types =[];
for (item_type in items) types.push(item_type);
sort(types, a=>mappings[a].order);
for (item_type of types){
let map = mappings[item_type];
if (map.to && map.to!=elt.id) continue;
for (item of items[item_type]){
let li = document.createElement("li");
li.className="stick l"+ level;
li.setAttribute("data-path",path+"/"+item[0])
let img1 = document.createElement("img");
if (map.expand){
li.classList.add("can_fold");
img1.src=img_fold;
img1.onclick=function(){ li_folding(img1,true)};
}
else {
img1.src=img_empty;
}
li.appendChild(img1);
let img2 = document.createElement("img");
img2.src=map.icon;
li.appendChild(img2);
let a = document.createElement("a");
let href=path+map.link.replace("$",item[0]);
a.href=href;
a.onclick=function(){set_page(href); return false;}
a.textContent=" "+item[0];
li.appendChild(a);
ul.appendChild(li);
}
if (map.to && map.to==elt.id) break;
}
elt.insertAdjacentElement("afterend",ul);
return ul
}
}
// Support unfolding in the sidebar
function set_unfold_sidebar(elt = null) {
if (!elt){
elt = document.querySelector("#sidebar");
}
for (item of elt.querySelectorAll("li.can_fold")) {
let arrow = item.firstElementChild;
li_folding(arrow);
arrow.addEventListener("click", function () {
li_folding(arrow,true);
}, false);
}
}
function li_folding(arrow, switch_state=false) {
let li = arrow.parentElement;
if (switch_state){
li.classList.toggle("open");
}
if (li.classList.contains("open")) {
arrow.setAttribute("src", img_open);
let ul = li.nextElementSibling
if (!ul || ul.tagName!="UL"){
ul=load_node(li)
set_unfold_sidebar(li);
}
}
else {
arrow.setAttribute("src", img_fold);
}
}
// Load content from a rustdoc page
async function set_page(url){
current_path = url.replace(/(.*)\/.*/,"$1");
sidebar_current(url);
let response = await fetch(url);
let html = await response.text();
page = new DOMParser().parseFromString(html, "text/html");
console.log(page);
refresh_content(page);
content.scrollTo(0,0);
}
function refresh_content(loaded_page){
var page = loaded_page.cloneNode(true);
// update title
var title = document.getElementById("title_item");
var page_type = page.querySelector(".fqn .in-band").firstChild.textContent;
for (map in mappings){
if (mappings[map].text==page_type){
page_type=map;
break;
}
}
title.innerHTML="";
title.appendChild(page.querySelector(".fqn .in-band"));
// update declarartion
let decl_src=page.querySelector(".type-decl");
if (decl_src){
document.getElementById("declaration_section").style.display="block";
var decl_dest = document.getElementById("declaration");
decl_dest.innerHTML="";
decl_dest.appendChild(decl_src);
}
else{
document.getElementById("declaration_section").style.display="none";
}
// update items
let items = page.querySelectorAll(".module-item");
if (items.length>0){
document.getElementById("item_section").style.display="block";
let item_table = document.getElementById("item_table");
item_table.innerHTML="";
for (item of items){
let a = item.firstChild.firstChild;
let map= mappings[a.className];
if (map.to) {continue;}
let new_tr = document.getElementById("item_row").content.firstElementChild.cloneNode(true);
new_tr.children[0].firstChild.src=map.icon;
new_tr.children[1].firstChild.textContent=a.textContent;
let href=current_path+map.link.replace("$",a.textContent);
new_tr.children[1].firstChild.href=href;
new_tr.children[1].firstChild.onclick=function(){
set_page(href);
return false;
};
new_tr.children[2].appendChild(item.children[1]);
item_table.appendChild(new_tr);
}
}
else {
document.getElementById("item_section").style.display="none";
}
// update description
var desc = document.getElementById("description");
desc.innerHTML="";
desc.appendChild(page.querySelector(".docblock"));
//update implementation list
let line=document.getElementById("impl_list");
line.innerHTML="";
let impl_hidden = localStorage.getItem("impl_hidden");
if (!impl_hidden) impl_hidden=[];
let impl_inline={};
for (item of page.querySelectorAll("h3.impl")){
let short = make_short_impl(item.cloneNode(true));
let trait = short.getAttribute("data-trait");
if (trait){
if (!impl_inline[trait]){
impl_inline[trait]={
hidden:impl_hidden.includes(trait),
display:short,
detail:[]
};
}
impl_inline[trait].detail.push(item.cloneNode(true));
}
}
for (trait in impl_inline) {
span = document.createElement("span");
span.appendChild(impl_inline[trait].display);
popup = document.createElement("div");
popup.style.display="none";
var first = true;
for (impl of impl_inline[trait].detail) {
if (first==true){
first=false;
}
else {
popup.appendChild(document.createElement("hr"));
}
popup.appendChild(impl);
}
span.appendChild(popup);
setPopup(impl_inline[trait].display, popup);
line.appendChild(span);
line.appendChild(document.createTextNode(", "));
}
// update methods information
var methods_begin = page.querySelector("#methods,#deref-methods,#implementations,#synthetic-implementations,#blanket-implementations");
if (methods_begin){
document.getElementById("method_section").style.display="block";
document.getElementById("menu_methods").style.display="block";
// update method detail
var methods = document.getElementById("methods");
methods.style.display="block";
methods.innerHTML="";
var item=methods_begin;
do {
methods.appendChild(item.cloneNode(true));
} while (item = item.nextSibling)
// update method summary
let table = document.querySelector("#method_table")
table.innerHTML="";
table.className= group_mode=="fn" ? "group-fn" : "group-impl";
var list = [];
var cur_impl;
for (item of page.querySelectorAll("h3.impl, h4.method, h2#deref-methods")){
if (item.tagName=="H4"){
if (blanket_mode=="hidden" && item.parentNode && item.parentNode.parentNode && item.parentNode.parentNode.id=="blanket-implementations-list"){
continue;
}
list.push(make_fn_row(item,cur_impl));
}
if (item.tagName!="H4" || !item.nextElementSibling){
if (blanket_mode=="hidden" && item.parentNode && item.parentNode.id=="blanket-implementations-list"){
continue;
}
if (group_mode=="impl" && cur_impl){
table.appendChild(make_impl_row(cur_impl, list.length>0));
flush_fn_rows(list,table);
}
cur_impl=item;
}
}
flush_fn_rows(list,table);
}
else {
document.getElementById("method_section").style.display="none";
document.getElementById("methods").style.display="none";
document.getElementById("menu_methods").style.display="none";
}
if (!decl_src && !methods_begin && items.length==0){
document.getElementById("menu_summary").style.display="none";
}
// set dynamic elements
set_unfold_summary();
set_popups();
set_slider();
set_scrolling();
}
function flush_fn_rows(list,table){
if (sort_mode=="sort"){
sort(list,a=>a.querySelector(".shortname").textContent);
}
var parent=null;
for (var i=0; i<list.length; i++) {
if (sort_mode=="sort" && i+1<list.length){
let cur_name = list[i].querySelector(".shortname").textContent;
let next_name= list[i+1].querySelector(".shortname").textContent;
if (cur_name==next_name){
if (parent==null){
parent=list[i].cloneNode(true);
parent.className="can_fold";
parent.querySelector(".shortimpl").textContent="…";
parent.querySelector(".fullimpl").textContent="Multiple implementations";
table.appendChild(parent);
}
list[i].className="expanded";
let parent_desc=parent.querySelector(".shortdesc");
let child_desc=list[i].querySelector(".shortdesc");
if (child_desc.textContent != parent_desc.textContent) {
parent_desc.textContent="…"
}
}
else if (parent) {
parent=null;
list[i].className="expanded";
}
}
if (group_mode=="impl"){
list[i].className="expanded";
}
table.appendChild(list[i]);
}
list.length=0;
}
function make_impl_row(item, expand){
// Instantiate template
var new_tr = document.getElementById("impl_row").content.cloneNode(true);
var label;
if (item.tagName=="H2") {
label = item.innerHTML;
}
else {
label = item.firstElementChild.innerHTML;
label = label.replace(/( )+/g," ");
}
if (!expand){
new_tr.firstElementChild.children[0].innerHTML="";
}
new_tr.firstElementChild.children[1].innerHTML = label;
return new_tr;
}
function make_fn_row(item, cur_impl){
// Insantiate template
var new_tr = document.getElementById("fn_row").content.cloneNode(true);
new_tr=new_tr.firstElementChild;
//shortname
new_tr.children[2].firstElementChild.appendChild(item.querySelector(".fnname").firstChild.cloneNode(true));
//shortimpl
new_tr.children[3].appendChild(make_short_impl(cur_impl));
//shortdesc
var next = item.nextElementSibling;
if (next.querySelector(".stability .unstable")){
new_tr.children[4].appendChild(document.createTextNode("🔬"));
next=next.nextElementSibling;
}
if (next.querySelector(".stability .deprecated")){
new_tr.children[4].appendChild(document.createTextNode("⚠️"));
next=next.nextElementSibling;
}
var text = next.textContent.split(".",2)[0] + ".";
new_tr.children[4].appendChild(document.createTextNode(text));
//fullname
new_tr.children[5].appendChild(item.cloneNode(true));
//fullimpl
new_tr.children[6].appendChild(cur_impl.cloneNode(true));
return new_tr;
}
function make_short_impl(elt) {
let a = document.querySelectorAll("#title_item .in-band a")
let main_type=a[a.length-1].textContent;
let out = document.createElement("span");
let text;
let info = false;
let prefix = "";
if (elt.tagName=="H2") {
prefix = "from";
text = elt.textContent.trim();
text = text.replace(/.*?=(.*).*>/,"$1");
}
else {
text = elt.querySelector(".in-band").textContent.trim();
text = text.replace(/\s/g," ");
//impl arguments
let pos = 4;
var impl_args="";
if (text.startsWith("impl<")){
pos = get_block(text,4,"<",">");
impl_args = text.substring(4,pos);
if (impl_args.includes(":")) info=true;
}
text=text.substring(pos).trim();
//where clause
var pos_where = text.indexOf(" where ");
var where_clause
if (pos_where > 0){
where_clause = text.substring(pos_where+7);
text = text.substring(0,pos_where);
info=true;
}
//for clause
let pos_for = text.indexOf(" for ");
var for_clause;
var short_for_clause;
if (pos_for > 0) {
for_clause = text.substring(pos_for+5).trim();
text = text.substring(0,pos_for);
if (for_clause!=main_type+impl_args) info=true;
short_for_clause = for_clause.replace(/<.*/,"<…>");
}
//implemented trait
var impl_trait=text.trim();
var short_impl_trait=impl_trait.replace(/<.*/,"<…>");
if (impl_trait.startsWith(main_type) && impl_trait!=main_type+impl_args){
info=true
}
//final text
if (impl_trait.startsWith(main_type)){
if (for_clause && !for_clause.includes(main_type)){
prefix="for";
text=short_for_clause;
}
else {
text="";
}
}
else {
text=short_impl_trait;
out.setAttribute("data-trait",short_impl_trait.replace(/<.*/,""));
}
}
if (prefix!="") {
let elt_prefix = document.createElement("span");
elt_prefix.className="prefix";
elt_prefix.appendChild(document.createTextNode(prefix+" "));
out.appendChild(elt_prefix);
}
out.appendChild(document.createTextNode(text));
if (info) {
out.appendChild(document.createTextNode("\xA0"))
let sup = document.createElement("sup");
sup.appendChild(document.createTextNode("🛈"));
out.appendChild(sup);
}
return out;
}
function get_block(str, start, open, close){
if (str[start]!=open) return -1;
let count =1;
var pos;
for (pos=start+1; count>0; pos++){
if (pos>=str.length) return -1;
if (str[pos]==open) count++;
if (str[pos]==close) count--;
}
return pos;
}
//Support unfolding in the item summary
function set_unfold_summary(){
for (let line of document.querySelectorAll(".summary .can_fold")) {
let arrow = line.querySelector("img");
if (arrow) {
tr_folding(arrow, false);
arrow.addEventListener("click", function(evt){
tr_folding(evt.target,true);
}, false);
}
}
}
function tr_folding(img, switch_state){
var tr = img.parentElement.parentElement;
var display;
if (switch_state) tr.classList.toggle("open")
if (tr.classList.contains("open")) {
img.src=img_open;
display="table-row";
}
else {
img.src=img_fold;
display="none";
}
while ((tr=tr.nextElementSibling) && tr.className.includes("expanded")){
tr.style.display=display;
}
}
function set_popups(){
for (let line of document.querySelectorAll(".summary tr")){
//tooltip on method name
let name = line.querySelector(".shortname");
let fname = line.querySelector(".fullname");
let impl = line.querySelector(".shortimpl");
let fimpl = line.querySelector(".fullimpl");
if (name && fname) setPopup(name,fname);
if (impl && fimpl) setPopup(impl,fimpl);
if(fname){
let target = fname.querySelector("h4");
if (target) {
let old_id = target.id;
target.id = "popup_"+old_id;
//name.querySelector("a").href = "#"+old_id;
name.querySelector("a").addEventListener("click",function(){stick_aware_link(old_id)});
}
}
}
}
// Handling of the slider
var dragging = false;
var cratetree = document.getElementById("cratetree");
function set_slider(){
document.body.addEventListener("mousemove", drag_pending);
document.body.addEventListener("mouseup", drag_end);
document.getElementById("slider").addEventListener("mousedown", drag_start);
}
function drag_start(evt) {
document.body.style.setProperty("user-select", "none");
dragging = true;
}
function drag_end(evt) {
if (dragging) {
dragging = false;
localStorage.setItem("slider", evt.pageX);
drag_pending(evt);
document.body.style.setProperty("user-select", "auto");
}
}
function drag_pending(evt) {
if (dragging) {
document.body.style.setProperty("--sidebar-width", evt.pageX + "px");
cratetree.scrollTo({ left: 0 });
}
}
// Description popup
let display_popup_timeout;
let hide_popup_timeout;
let infobox = document.getElementById("infobox");
function setPopup(elt, content) {
elt.addEventListener("mouseenter", function (evt) {
display_popup_timeout = setTimeout(function(){
let x = window.scrollX + evt.target.getBoundingClientRect().left
let y = window.scrollY + evt.target.getBoundingClientRect().top // Y
infobox.innerHTML=content.innerHTML;
infobox.style.display="block";
infobox.style.left="calc("+x+"px + 2.5em)";
infobox.style.top="calc("+y+"px + 1.25em)";
},600);
}, false);
elt.addEventListener("mouseleave", function (evt) {
clearTimeout(display_popup_timeout);
hide_popup_timeout = setTimeout(function(){
infobox.style.display="none";
},200);
}, false);
}
infobox.addEventListener("mouseenter", function (evt) {
clearTimeout(hide_popup_timeout);
}, false);
infobox.addEventListener("mouseleave", function (evt) {
infobox.style.display="none";
}, false);
// Scrolling management (stick + menubar color)
function set_scrolling(){
content.addEventListener("scroll",handle_scrolling);
handle_scrolling();
}
function handle_scrolling(evt){
manage_color(document.querySelector("#menu_summary"), document.querySelector("#summary"));
manage_color(document.querySelector("#menu_description"), document.querySelector("#description"));
manage_color(document.querySelector("#menu_methods"), document.querySelector("#methods"));
manage_stick();
}
function manage_color(menu_item, item){
let view_begin = content.scrollTop;
let view_end = view_begin + content.clientHeight;
let elt_begin = item.offsetTop - content.clientTop;
let elt_end = elt_begin + item.offsetHeight;
let elt_size = elt_end - elt_begin;
// compute item_displayed_height / viewable_height
var ratio;
if (elt_begin<view_begin) {
if (elt_end<view_begin) {
ratio=0;
}
else if (elt_end<view_end) {
ratio = Math.max(
(elt_end-view_begin)/content.clientHeight,
(elt_end-view_begin)/elt_size
);
}
else{
ratio=1;
}
}
else if (elt_begin<view_end){
if (elt_end<view_end) {
ratio=1;
}
else {
ratio = Math.max(
(view_end-elt_begin)/content.clientHeight,
(view_end-elt_begin)/elt_size
);
}
}else {
ratio = 0;
}
// compute item_displayed_height / item_height
menu_item.style.setProperty("background-color", "rgba(156,194,229,"+ratio+")");
}
var stuck_item=null;
var stuck_original;
function manage_stick(){
let impl_list = document.querySelectorAll("#methods .impl");
let globalOffset = document.querySelector("#summary").offsetTop;
for (var impl of impl_list){
let old = content.scrollTop;
if (impl.offsetTop-globalOffset<=content.scrollTop+2){
impl.className="impl stuck";
}
else {
impl.className="impl sticky";
}
content.scrollTop=old;
}
}
function stick_aware_link(id){
let item = document.getElementById(id);
let item_impl = item.parentElement.previousElementSibling
let impl_list = document.querySelectorAll("#methods .impl");
for (cur_impl of impl_list){
cur_impl.className="impl stuck";
if (cur_impl==item_impl) break;
}
content.scrollTop=item.offsetTop-content.offsetTop-36;
return false;
}
//
function switch_group(evt){
if (group_mode == "fn") {
group_mode="impl";
document.body.style.setProperty("--group-impl", "unset");
document.body.style.setProperty("--group-fn", "none");