Skip to content

Commit 4895855

Browse files
committed
Address comments
1 parent 536dc49 commit 4895855

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn parse<'a>(
154154

155155
let symbol = if variants.len() > 0 {
156156
if let Some(c) = c {
157-
variants.insert(0, (ModifierSet::empty(), c));
157+
variants.insert(0, (ModifierSet::default(), c));
158158
}
159159
Symbol::Multi(variants)
160160
} else {

src/lib.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
/*!
2-
Human-friendly notation for Unicode symbols.
3-
4-
## Model
5-
A [`Symbol`] is a collection of one or more _variants_.
6-
Each variant is identified by a set of _modifiers_ (see [`ModifierSet`])
7-
and has a single character as its value.
8-
The modifiers themselves can in principle be any non-empty strings
9-
that don't contain the character `.`, but codex only defines
10-
ones that are entirely made of ASCII alphabetical characters.
11-
*/
1+
//! Human-friendly notation for Unicode symbols.
2+
//!
3+
//! ## Model
4+
//! A [`Symbol`] is a collection of one or more _variants_.
5+
//! Each variant is identified by a set of [_modifiers_](ModifierSet)
6+
//! and has a single character as its value.
7+
//! The modifiers themselves can in principle be any non-empty strings
8+
//! that don't contain the character `.`, but codex only defines
9+
//! ones that are entirely made of ASCII alphabetical characters.
1210
1311
include!("shared.rs");
1412

@@ -34,13 +32,6 @@ impl Module {
3432
}
3533
}
3634

37-
impl<'a> ModifierSet<&'a str> {
38-
/// Iterate over the list of modifiers with the original lifetime.
39-
pub fn to_iter(self) -> impl Iterator<Item = &'a str> {
40-
self.0.split('.').filter(|s| !s.is_empty())
41-
}
42-
}
43-
4435
impl Symbol {
4536
/// Get the symbol's character for a given set of modifiers.
4637
pub fn get(&self, modifs: ModifierSet<&str>) -> Option<char> {
@@ -61,7 +52,7 @@ impl Symbol {
6152
Self::Multi(sl) => Variants::Multi(sl.iter()),
6253
};
6354
std::iter::from_fn(move || match &mut iter {
64-
Variants::Single(iter) => Some((ModifierSet::empty(), iter.next()?)),
55+
Variants::Single(iter) => Some((ModifierSet::default(), iter.next()?)),
6556
Variants::Multi(iter) => iter.next().copied(),
6657
})
6758
}

src/shared.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::ops::{AddAssign, Deref};
2-
31
macro_rules! declare_types {
42
($(<$lt:lifetime>)?
53
$(derive($($Der:ident),*),)?
@@ -51,7 +49,18 @@ macro_rules! declare_types {
5149
#[derive(Debug, Copy, Clone)]
5250
pub struct ModifierSet<S>(S);
5351

54-
impl<S: Deref<Target = str>> ModifierSet<S> {
52+
impl<S: Default> Default for ModifierSet<S> {
53+
/// Construct the default modifier set.
54+
///
55+
/// This is typically the empty set,
56+
/// though the remark from [`Self::new_unchecked`] applies
57+
/// since `S::default()` could technically be anything.
58+
fn default() -> Self {
59+
Self(S::default())
60+
}
61+
}
62+
63+
impl<S: std::ops::Deref<Target = str>> ModifierSet<S> {
5564
/// Convert the underlying string to a slice.
5665
pub fn as_deref(&self) -> ModifierSet<&str> {
5766
ModifierSet(&self.0)
@@ -68,14 +77,6 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
6877
Self(s)
6978
}
7079

71-
/// Construct an empty modifier set.
72-
pub fn empty() -> Self
73-
where
74-
S: Default,
75-
{
76-
Self(S::default())
77-
}
78-
7980
/// Whether `self` is empty.
8081
pub fn is_empty(&self) -> bool {
8182
self.0.is_empty()
@@ -88,7 +89,7 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
8889
/// `modifier` is not empty and doesn't contain the character `.`.
8990
pub fn add_unchecked(&mut self, m: &str)
9091
where
91-
S: for<'a> AddAssign<&'a str>,
92+
S: for<'a> std::ops::AddAssign<&'a str>,
9293
{
9394
if !self.0.is_empty() {
9495
self.0 += ".";
@@ -136,8 +137,8 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
136137
total += 1;
137138
}
138139

139-
let score = (matching, core::cmp::Reverse(total));
140-
if best_score.map_or(true, |b| score > b) {
140+
let score = (matching, std::cmp::Reverse(total));
141+
if best_score.is_none_or(|b| score > b) {
141142
best = Some(candidate.1);
142143
best_score = Some(score);
143144
}
@@ -146,3 +147,10 @@ impl<S: Deref<Target = str>> ModifierSet<S> {
146147
best
147148
}
148149
}
150+
151+
impl<'a> ModifierSet<&'a str> {
152+
/// Iterate over the list of modifiers with the original lifetime.
153+
pub fn to_iter(self) -> impl Iterator<Item = &'a str> {
154+
self.0.split('.').filter(|s| !s.is_empty())
155+
}
156+
}

0 commit comments

Comments
 (0)