Skip to content

Commit 5844047

Browse files
committed
Update slotmap
1 parent 4fd5d3f commit 5844047

File tree

8 files changed

+275
-287
lines changed

8 files changed

+275
-287
lines changed

Cargo.lock

Lines changed: 234 additions & 246 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/library/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
authors = ["Vincent Prouillet <[email protected]>"]
55

66
[dependencies]
7-
slotmap = "0.2"
7+
slotmap = "0.4"
88
rayon = "1"
99
chrono = { version = "0.4", features = ["serde"] }
1010
tera = "1.0.0-beta.10"

components/library/src/content/page.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::HashMap;
33
use std::path::{Path, PathBuf};
44

55
use regex::Regex;
6-
use slotmap::Key;
6+
use slotmap::DefaultKey;
77
use slug::slugify;
88
use tera::{Context as TeraContext, Tera};
99

@@ -35,7 +35,7 @@ pub struct Page {
3535
/// The front matter meta-data
3636
pub meta: PageFrontMatter,
3737
/// The list of parent sections
38-
pub ancestors: Vec<Key>,
38+
pub ancestors: Vec<DefaultKey>,
3939
/// The actual content of the page, in markdown
4040
pub raw_content: String,
4141
/// All the non-md files we found next to the .md file
@@ -58,13 +58,13 @@ pub struct Page {
5858
/// as summary
5959
pub summary: Option<String>,
6060
/// The earlier page, for pages sorted by date
61-
pub earlier: Option<Key>,
61+
pub earlier: Option<DefaultKey>,
6262
/// The later page, for pages sorted by date
63-
pub later: Option<Key>,
63+
pub later: Option<DefaultKey>,
6464
/// The lighter page, for pages sorted by weight
65-
pub lighter: Option<Key>,
65+
pub lighter: Option<DefaultKey>,
6666
/// The heavier page, for pages sorted by weight
67-
pub heavier: Option<Key>,
67+
pub heavier: Option<DefaultKey>,
6868
/// Toc made from the headings of the markdown file
6969
pub toc: Vec<Heading>,
7070
/// How many words in the raw content
@@ -76,7 +76,7 @@ pub struct Page {
7676
/// Corresponds to the lang in the {slug}.{lang}.md file scheme
7777
pub lang: String,
7878
/// Contains all the translated version of that page
79-
pub translations: Vec<Key>,
79+
pub translations: Vec<DefaultKey>,
8080
/// Contains the internal links that have an anchor: we can only check the anchor
8181
/// after all pages have been built and their ToC compiled. The page itself should exist otherwise
8282
/// it would have errored before getting there

components/library/src/content/section.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::HashMap;
22
use std::path::{Path, PathBuf};
33

4-
use slotmap::Key;
4+
use slotmap::DefaultKey;
55
use tera::{Context as TeraContext, Tera};
66

77
use config::Config;
@@ -38,13 +38,13 @@ pub struct Section {
3838
/// All the non-md files we found next to the .md file as string for use in templates
3939
pub serialized_assets: Vec<String>,
4040
/// All direct pages of that section
41-
pub pages: Vec<Key>,
41+
pub pages: Vec<DefaultKey>,
4242
/// All pages that cannot be sorted in this section
43-
pub ignored_pages: Vec<Key>,
43+
pub ignored_pages: Vec<DefaultKey>,
4444
/// The list of parent sections
45-
pub ancestors: Vec<Key>,
45+
pub ancestors: Vec<DefaultKey>,
4646
/// All direct subsections
47-
pub subsections: Vec<Key>,
47+
pub subsections: Vec<DefaultKey>,
4848
/// Toc made from the headings of the markdown file
4949
pub toc: Vec<Heading>,
5050
/// How many words in the raw content
@@ -56,7 +56,7 @@ pub struct Section {
5656
/// Corresponds to the lang in the _index.{lang}.md file scheme
5757
pub lang: String,
5858
/// Contains all the translated version of that section
59-
pub translations: Vec<Key>,
59+
pub translations: Vec<DefaultKey>,
6060
/// Contains the internal links that have an anchor: we can only check the anchor
6161
/// after all pages have been built and their ToC compiled. The page itself should exist otherwise
6262
/// it would have errored before getting there

components/library/src/library.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::{HashMap, HashSet};
22
use std::path::{Path, PathBuf};
33

4-
use slotmap::{DenseSlotMap, Key};
4+
use slotmap::{DenseSlotMap, DefaultKey};
55

66
use front_matter::SortBy;
77

@@ -19,13 +19,13 @@ use sorting::{find_siblings, sort_pages_by_date, sort_pages_by_weight};
1919
#[derive(Debug)]
2020
pub struct Library {
2121
/// All the pages of the site
22-
pages: DenseSlotMap<Page>,
22+
pages: DenseSlotMap<DefaultKey, Page>,
2323
/// All the sections of the site
24-
sections: DenseSlotMap<Section>,
24+
sections: DenseSlotMap<DefaultKey, Section>,
2525
/// A mapping path -> key for pages so we can easily get their key
26-
pub paths_to_pages: HashMap<PathBuf, Key>,
26+
pub paths_to_pages: HashMap<PathBuf, DefaultKey>,
2727
/// A mapping path -> key for sections so we can easily get their key
28-
pub paths_to_sections: HashMap<PathBuf, Key>,
28+
pub paths_to_sections: HashMap<PathBuf, DefaultKey>,
2929
/// Whether we need to look for translations
3030
is_multilingual: bool,
3131
}
@@ -42,38 +42,38 @@ impl Library {
4242
}
4343

4444
/// Add a section and return its Key
45-
pub fn insert_section(&mut self, section: Section) -> Key {
45+
pub fn insert_section(&mut self, section: Section) -> DefaultKey {
4646
let path = section.file.path.clone();
4747
let key = self.sections.insert(section);
4848
self.paths_to_sections.insert(path, key);
4949
key
5050
}
5151

5252
/// Add a page and return its Key
53-
pub fn insert_page(&mut self, page: Page) -> Key {
53+
pub fn insert_page(&mut self, page: Page) -> DefaultKey {
5454
let path = page.file.path.clone();
5555
let key = self.pages.insert(page);
5656
self.paths_to_pages.insert(path, key);
5757
key
5858
}
5959

60-
pub fn pages(&self) -> &DenseSlotMap<Page> {
60+
pub fn pages(&self) -> &DenseSlotMap<DefaultKey, Page> {
6161
&self.pages
6262
}
6363

64-
pub fn pages_mut(&mut self) -> &mut DenseSlotMap<Page> {
64+
pub fn pages_mut(&mut self) -> &mut DenseSlotMap<DefaultKey, Page> {
6565
&mut self.pages
6666
}
6767

6868
pub fn pages_values(&self) -> Vec<&Page> {
6969
self.pages.values().collect::<Vec<_>>()
7070
}
7171

72-
pub fn sections(&self) -> &DenseSlotMap<Section> {
72+
pub fn sections(&self) -> &DenseSlotMap<DefaultKey, Section> {
7373
&self.sections
7474
}
7575

76-
pub fn sections_mut(&mut self) -> &mut DenseSlotMap<Section> {
76+
pub fn sections_mut(&mut self) -> &mut DenseSlotMap<DefaultKey, Section> {
7777
&mut self.sections
7878
}
7979

@@ -336,7 +336,7 @@ impl Library {
336336
}
337337

338338
/// Only used in tests
339-
pub fn get_section_key<P: AsRef<Path>>(&self, path: P) -> Option<&Key> {
339+
pub fn get_section_key<P: AsRef<Path>>(&self, path: P) -> Option<&DefaultKey> {
340340
self.paths_to_sections.get(path.as_ref())
341341
}
342342

@@ -349,27 +349,27 @@ impl Library {
349349
.get_mut(self.paths_to_sections.get(path.as_ref()).cloned().unwrap_or_default())
350350
}
351351

352-
pub fn get_section_by_key(&self, key: Key) -> &Section {
352+
pub fn get_section_by_key(&self, key: DefaultKey) -> &Section {
353353
self.sections.get(key).unwrap()
354354
}
355355

356-
pub fn get_section_mut_by_key(&mut self, key: Key) -> &mut Section {
356+
pub fn get_section_mut_by_key(&mut self, key: DefaultKey) -> &mut Section {
357357
self.sections.get_mut(key).unwrap()
358358
}
359359

360-
pub fn get_section_path_by_key(&self, key: Key) -> &str {
360+
pub fn get_section_path_by_key(&self, key: DefaultKey) -> &str {
361361
&self.get_section_by_key(key).file.relative
362362
}
363363

364364
pub fn get_page<P: AsRef<Path>>(&self, path: P) -> Option<&Page> {
365365
self.pages.get(self.paths_to_pages.get(path.as_ref()).cloned().unwrap_or_default())
366366
}
367367

368-
pub fn get_page_by_key(&self, key: Key) -> &Page {
368+
pub fn get_page_by_key(&self, key: DefaultKey) -> &Page {
369369
self.pages.get(key).unwrap()
370370
}
371371

372-
pub fn get_page_mut_by_key(&mut self, key: Key) -> &mut Page {
372+
pub fn get_page_mut_by_key(&mut self, key: DefaultKey) -> &mut Page {
373373
self.pages.get_mut(key).unwrap()
374374
}
375375

components/library/src/pagination/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use slotmap::Key;
3+
use slotmap::DefaultKey;
44
use tera::{to_value, Context, Tera, Value};
55

66
use config::Config;
@@ -44,7 +44,7 @@ impl<'a> Pager<'a> {
4444
#[derive(Clone, Debug, PartialEq)]
4545
pub struct Paginator<'a> {
4646
/// All pages in the section/taxonomy
47-
all_pages: &'a [Key],
47+
all_pages: &'a [DefaultKey],
4848
/// Pages split in chunks of `paginate_by`
4949
pub pagers: Vec<Pager<'a>>,
5050
/// How many content pages on a paginated page at max

components/library/src/sorting.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::cmp::Ordering;
22

33
use chrono::NaiveDateTime;
44
use rayon::prelude::*;
5-
use slotmap::Key;
5+
use slotmap::DefaultKey;
66

77
use content::Page;
88

@@ -21,7 +21,7 @@ pub fn sort_actual_pages_by_date(a: &&Page, b: &&Page) -> Ordering {
2121
/// Takes a list of (page key, date, permalink) and sort them by dates if possible
2222
/// Pages without date will be put in the unsortable bucket
2323
/// The permalink is used to break ties
24-
pub fn sort_pages_by_date(pages: Vec<(&Key, Option<NaiveDateTime>, &str)>) -> (Vec<Key>, Vec<Key>) {
24+
pub fn sort_pages_by_date(pages: Vec<(&DefaultKey, Option<NaiveDateTime>, &str)>) -> (Vec<DefaultKey>, Vec<DefaultKey>) {
2525
let (mut can_be_sorted, cannot_be_sorted): (Vec<_>, Vec<_>) =
2626
pages.into_par_iter().partition(|page| page.1.is_some());
2727

@@ -40,7 +40,7 @@ pub fn sort_pages_by_date(pages: Vec<(&Key, Option<NaiveDateTime>, &str)>) -> (V
4040
/// Takes a list of (page key, weight, permalink) and sort them by weight if possible
4141
/// Pages without weight will be put in the unsortable bucket
4242
/// The permalink is used to break ties
43-
pub fn sort_pages_by_weight(pages: Vec<(&Key, Option<usize>, &str)>) -> (Vec<Key>, Vec<Key>) {
43+
pub fn sort_pages_by_weight(pages: Vec<(&DefaultKey, Option<usize>, &str)>) -> (Vec<DefaultKey>, Vec<DefaultKey>) {
4444
let (mut can_be_sorted, cannot_be_sorted): (Vec<_>, Vec<_>) =
4545
pages.into_par_iter().partition(|page| page.1.is_some());
4646

@@ -57,7 +57,7 @@ pub fn sort_pages_by_weight(pages: Vec<(&Key, Option<usize>, &str)>) -> (Vec<Key
5757
}
5858

5959
/// Find the lighter/heavier and earlier/later pages for all pages having a date/weight
60-
pub fn find_siblings(sorted: &[Key]) -> Vec<(Key, Option<Key>, Option<Key>)> {
60+
pub fn find_siblings(sorted: &[DefaultKey]) -> Vec<(DefaultKey, Option<DefaultKey>, Option<DefaultKey>)> {
6161
let mut res = Vec::with_capacity(sorted.len());
6262
let length = sorted.len();
6363

components/library/src/taxonomies/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use slotmap::Key;
3+
use slotmap::DefaultKey;
44
use slug::slugify;
55
use tera::{Context, Tera};
66

@@ -44,15 +44,15 @@ pub struct TaxonomyItem {
4444
pub name: String,
4545
pub slug: String,
4646
pub permalink: String,
47-
pub pages: Vec<Key>,
47+
pub pages: Vec<DefaultKey>,
4848
}
4949

5050
impl TaxonomyItem {
5151
pub fn new(
5252
name: &str,
5353
taxonomy: &TaxonomyConfig,
5454
config: &Config,
55-
keys: Vec<Key>,
55+
keys: Vec<DefaultKey>,
5656
library: &Library,
5757
) -> Self {
5858
// Taxonomy are almost always used for blogs so we filter by dates
@@ -113,7 +113,7 @@ impl Taxonomy {
113113
fn new(
114114
kind: TaxonomyConfig,
115115
config: &Config,
116-
items: HashMap<String, Vec<Key>>,
116+
items: HashMap<String, Vec<DefaultKey>>,
117117
library: &Library,
118118
) -> Taxonomy {
119119
let mut sorted_items = vec![];

0 commit comments

Comments
 (0)