Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkeldenker committed Feb 28, 2024
1 parent 25c0344 commit 99dc06e
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 34 deletions.
2 changes: 2 additions & 0 deletions crates/core/src/crawler/file_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ where

let file = std::fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.read(true)
.open(path.as_ref().join(DATA_KEY))?;
Expand Down Expand Up @@ -103,6 +104,7 @@ impl FilePointer {

let file = std::fs::OpenOptions::new()
.create(true)
.truncate(false)
.write(true)
.read(true)
.open(path.as_ref().join(POINTER_KEY))?;
Expand Down
1 change: 1 addition & 0 deletions crates/core/src/external_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl TempFile {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&path)?,
path,
})
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/query/pattern_query/scorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use super::SmallPatternPart;

pub enum PatternScorer {
Normal(NormalPatternScorer),
FastSiteDomain(FastSiteDomainPatternScorer),
FastSiteDomain(Box<FastSiteDomainPatternScorer>),
Everything(AllScorer),
EmptyField(EmptyFieldScorer),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/query/pattern_query/weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl tantivy::query::Weight for FastSiteDomainPatternWeight {
_boost: tantivy::Score,
) -> tantivy::Result<Box<dyn tantivy::query::Scorer>> {
if let Some(scorer) = self.pattern_scorer(reader)? {
Ok(Box::new(PatternScorer::FastSiteDomain(scorer)))
Ok(Box::new(PatternScorer::FastSiteDomain(Box::new(scorer))))
} else {
Ok(Box::new(EmptyScorer))
}
Expand Down
5 changes: 5 additions & 0 deletions crates/core/src/web_spell/stupid_backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl StupidBackoffTrainer {
}
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref().join("ngrams.bin"))?;

Expand All @@ -114,6 +115,7 @@ impl StupidBackoffTrainer {

let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref().join("rotated_ngrams.bin"))?;

Expand Down Expand Up @@ -235,13 +237,15 @@ impl StupidBackoff {

let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref().join("n_counts.bin"))?;

bincode::serialize_into(file, &n_counts)?;

let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref().join("ngrams.bin"))?;

Expand All @@ -257,6 +261,7 @@ impl StupidBackoff {

let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref().join("rotated_ngrams.bin"))?;

Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/web_spell/term_freqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl DictBuilder {
fn build<P: AsRef<Path>>(self, path: P) -> Result<StoredDict> {
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref())?;

Expand Down Expand Up @@ -87,6 +88,7 @@ impl StoredDict {
fn merge<P: AsRef<Path>>(dicts: Vec<Self>, path: P) -> Result<Self> {
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(path.as_ref())?;

Expand Down Expand Up @@ -349,6 +351,7 @@ impl TermDict {
let uuid = uuid::Uuid::new_v4();
let file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(self.path.join(format!("{}.dict", uuid)))?;

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/webgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl Meta {
let mut reader = BufReader::new(
File::options()
.create(true)
.truncate(false)
.write(true)
.read(true)
.open(path)
Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/webgraph/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ impl EdgeStore {
let edge_labels_file = File::options()
.read(true)
.create(true)
.truncate(false)
.write(true)
.open(path.as_ref().join("labels"))
.unwrap();
Expand All @@ -348,6 +349,7 @@ impl EdgeStore {
let edge_nodes_file = File::options()
.read(true)
.create(true)
.truncate(false)
.write(true)
.open(path.as_ref().join("nodes"))
.unwrap();
Expand Down
66 changes: 34 additions & 32 deletions crates/optics/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::fmt::Display;

use logos::{Lexer, Logos};

use super::{Error, Result};
Expand Down Expand Up @@ -54,39 +56,39 @@ pub enum Token<'a> {
Number(&'a str),
}

impl<'a> ToString for Token<'a> {
fn to_string(&self) -> String {
impl<'a> Display for Token<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Token::SemiColon => ";".to_string(),
Token::Comma => ",".to_string(),
Token::OpenBracket => "{".to_string(),
Token::CloseBracket => "}".to_string(),
Token::OpenParenthesis => "(".to_string(),
Token::CloseParenthesis => ")".to_string(),
Token::DiscardNonMatching => "DiscardNonMatching".to_string(),
Token::Rule => "Rule".to_string(),
Token::RankingPipeline => "RankingPipeline".to_string(),
Token::Ranking => "Ranking".to_string(),
Token::Stage => "Stage".to_string(),
Token::Signal => "Signal".to_string(),
Token::Field => "Field".to_string(),
Token::Matches => "Matches".to_string(),
Token::Site => "Site".to_string(),
Token::Url => "Url".to_string(),
Token::Domain => "Domain".to_string(),
Token::Title => "Title".to_string(),
Token::Description => "Description".to_string(),
Token::Content => "Content".to_string(),
Token::MicroformatTag => "MicroformatTag".to_string(),
Token::Schema => "Schema".to_string(),
Token::Action => "Action".to_string(),
Token::Boost => "Boost".to_string(),
Token::Downrank => "Downrank".to_string(),
Token::Discard => "Discard".to_string(),
Token::Like => "Like".to_string(),
Token::Dislike => "Dislike".to_string(),
Token::String(s) => format!("\"{s}\""),
Token::Number(n) => n.to_string(),
Token::SemiColon => f.write_str(";"),
Token::Comma => f.write_str(","),
Token::OpenBracket => f.write_str("{"),
Token::CloseBracket => f.write_str("}"),
Token::OpenParenthesis => f.write_str("("),
Token::CloseParenthesis => f.write_str(")"),
Token::DiscardNonMatching => f.write_str("DiscardNonMatching"),
Token::Rule => f.write_str("Rule"),
Token::RankingPipeline => f.write_str("RankingPipeline"),
Token::Ranking => f.write_str("Ranking"),
Token::Stage => f.write_str("Stage"),
Token::Signal => f.write_str("Signal"),
Token::Field => f.write_str("Field"),
Token::Matches => f.write_str("Matches"),
Token::Site => f.write_str("Site"),
Token::Url => f.write_str("Url"),
Token::Domain => f.write_str("Domain"),
Token::Title => f.write_str("Title"),
Token::Description => f.write_str("Description"),
Token::Content => f.write_str("Content"),
Token::MicroformatTag => f.write_str("MicroformatTag"),
Token::Schema => f.write_str("Schema"),
Token::Action => f.write_str("Action"),
Token::Boost => f.write_str("Boost"),
Token::Downrank => f.write_str("Downrank"),
Token::Discard => f.write_str("Discard"),
Token::Like => f.write_str("Like"),
Token::Dislike => f.write_str("Dislike"),
Token::String(s) => write!(f, "\"{s}\""),
Token::Number(n) => write!(f, "{n}"),
}
}
}
Expand Down

0 comments on commit 99dc06e

Please sign in to comment.