Skip to content

Commit

Permalink
update project
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Apr 12, 2023
1 parent 04d6b31 commit b6c819c
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 158 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "weekly"
16 changes: 8 additions & 8 deletions .github/workflows/ci-version.yml
Expand Up @@ -18,17 +18,17 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- 1.61
- stable
- nightly
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }}
features:
-
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
- run: cargo build --release
- run: cargo test --release
- run: cargo doc --release
- run: cargo test --release ${{ matrix.features }}
- run: cargo doc --release ${{ matrix.features }}
31 changes: 13 additions & 18 deletions .github/workflows/ci.yml
Expand Up @@ -9,24 +9,19 @@ jobs:
rustfmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt
- run: cargo fmt -- --check
- uses: actions-rust-lang/rustfmt@v1

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: clippy
- run: cargo clippy --all-targets --all-features -- -D warnings

Expand All @@ -39,17 +34,17 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- 1.61
- stable
- nightly
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }}
features:
-
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.toolchain }}
override: true
- run: cargo build
- run: cargo test
- run: cargo doc
- run: cargo test ${{ matrix.features }}
- run: cargo doc ${{ matrix.features }}
1 change: 1 addition & 0 deletions word-dictionary/Cargo.toml
Expand Up @@ -3,6 +3,7 @@ name = "word-dictionary"
version = "0.1.1"
authors = ["Magic Len <len@magiclen.org>"]
edition = "2021"
rust-version = "1.61"
repository = "https://github.com/magiclen/words-transformer-rs"
homepage = "https://magiclen.org/words-transformer-rs"
keywords = ["translation", "dictionary"]
Expand Down
61 changes: 56 additions & 5 deletions word-dictionary/rustfmt.toml
@@ -1,15 +1,66 @@
# array_width = 60
# attr_fn_like_width = 70
binop_separator = "Front"
blank_lines_lower_bound = 0
blank_lines_upper_bound = 1
brace_style = "PreferSameLine"
enum_discrim_align_threshold = 100
force_explicit_abi = false
force_multiline_blocks = true
# chain_width = 60
color = "Auto"
# comment_width = 100
condense_wildcard_suffixes = true
control_brace_style = "AlwaysSameLine"
empty_item_single_line = true
enum_discrim_align_threshold = 80
error_on_line_overflow = false
error_on_unformatted = false
# fn_call_width = 60
fn_params_layout = "Tall"
fn_single_line = false
force_explicit_abi = true
force_multiline_blocks = false
format_code_in_doc_comments = true
doc_comment_code_block_width = 80
format_generated_files = true
format_macro_matchers = true
format_macro_bodies = true
skip_macro_invocations = []
format_strings = true
hard_tabs = false
hex_literal_case = "Upper"
imports_indent = "Block"
imports_layout = "Mixed"
indent_style = "Block"
inline_attribute_width = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
match_block_trailing_comma = true
max_width = 100
merge_derives = true
imports_granularity = "Crate"
newline_style = "Unix"
normalize_comments = false
normalize_doc_attributes = true
overflow_delimited_expr = true
remove_nested_parens = true
reorder_impl_items = true
reorder_imports = true
group_imports = "StdExternalCrate"
reorder_modules = true
short_array_element_width_threshold = 10
# single_line_if_else_max_width = 50
space_after_colon = true
space_before_colon = false
spaces_around_ranges = false
struct_field_align_threshold = 80
struct_lit_single_line = false
# struct_lit_width = 18
# struct_variant_width = 35
tab_spaces = 4
trailing_comma = "Vertical"
trailing_semicolon = true
type_punctuation_density = "Wide"
use_field_init_shorthand = true
use_small_heuristics = "Off"
use_try_shorthand = true
use_small_heuristics = "Max"
use_try_shorthand = true
where_single_line = false
wrap_comments = false
54 changes: 21 additions & 33 deletions word-dictionary/src/errors.rs
@@ -1,27 +1,21 @@
use std::error::Error;
use std::fmt::{self, Display, Formatter};
use std::io;
use std::{
error::Error,
fmt::{self, Display, Formatter},
io,
};

#[derive(Debug)]
pub enum BrokenReason {
BadLeftString,
NoRightString,
BadRightString {
right_string: String,
},
Duplicated {
another_left_string: String,
},
BadRightString { right_string: String },
Duplicated { another_left_string: String },
}

#[derive(Debug)]
pub enum ReadError {
IOError(io::Error),
Broken {
line: usize,
left_string: String,
reason: BrokenReason,
},
Broken { line: usize, left_string: String, reason: BrokenReason },
}

impl From<io::Error> for ReadError {
Expand All @@ -44,26 +38,20 @@ impl Display for ReadError {
f.write_fmt(format_args!("broken at line {}, ", line))?;

match reason {
BrokenReason::BadLeftString => {
f.write_fmt(format_args!(
"the left string {:?} is not correct",
left_string
))
}
BrokenReason::NoRightString => {
f.write_fmt(format_args!(
BrokenReason::BadLeftString => f.write_fmt(format_args!(
"the left string {:?} is not correct",
left_string
)),
BrokenReason::NoRightString => f.write_fmt(format_args!(
"expected a \"=\" after the left string {:?} to concatenate a right string",
left_string
))
}
)),
BrokenReason::BadRightString {
right_string,
} => {
f.write_fmt(format_args!(
"the right string {:?} is not correct",
right_string
))
}
} => f.write_fmt(format_args!(
"the right string {:?} is not correct",
right_string
)),
BrokenReason::Duplicated {
another_left_string,
} => {
Expand All @@ -78,9 +66,9 @@ impl Display for ReadError {
left_string, another_left_string
))
}
}
},
}
}
},
}
}
}
Expand Down Expand Up @@ -112,7 +100,7 @@ impl Display for WriteError {
WriteError::BadRightString => f.write_str("the right word is not correct"),
WriteError::Duplicated => {
f.write_str("the pair of the left word and the right word is duplicated")
}
},
WriteError::Same => f.write_str("the left word is equal to the right word"),
}
}
Expand Down
43 changes: 21 additions & 22 deletions word-dictionary/src/lib.rs
Expand Up @@ -31,22 +31,23 @@ Althasol = 阿爾瑟索
```
*/

use std::fs::File;
use std::io::{BufRead, BufReader, ErrorKind, Write};
use std::path::PathBuf;
use std::{
fs::File,
io::{BufRead, BufReader, ErrorKind, Write},
path::PathBuf,
};

mod errors;

use trim_in_place::TrimInPlace;

pub use errors::*;
use trim_in_place::TrimInPlace;

#[derive(Debug)]
pub struct Dictionary {
/// The path of the dictionary file.
path: PathBuf,
path: PathBuf,
/// Left data.
left: Vec<String>,
left: Vec<String>,
/// Right data.
right: Vec<Vec<String>>,
}
Expand All @@ -56,9 +57,7 @@ impl Dictionary {
#[inline]
pub fn new<P: Into<PathBuf>>(path: P) -> Dictionary {
Dictionary {
path: path.into(),
left: Vec::new(),
right: Vec::new(),
path: path.into(), left: Vec::new(), right: Vec::new()
}
}
}
Expand Down Expand Up @@ -256,7 +255,7 @@ impl Dictionary {
Err(err) if err.kind() == ErrorKind::NotFound => {
// it is okay with a file not found error
return Ok(());
}
},
Err(err) => return Err(err.into()),
};

Expand Down Expand Up @@ -287,9 +286,9 @@ impl Dictionary {

if left_string.contains("-->") {
return Err(ReadError::Broken {
line: line_counter,
line: line_counter,
left_string: String::from(left_string),
reason: BrokenReason::BadLeftString,
reason: BrokenReason::BadLeftString,
});
}

Expand All @@ -299,9 +298,9 @@ impl Dictionary {

if let Some(index) = self.find_left_strictly(left_string, 0) {
return Err(ReadError::Broken {
line: line_counter,
line: line_counter,
left_string: String::from(left_string),
reason: BrokenReason::Duplicated {
reason: BrokenReason::Duplicated {
another_left_string: String::from(self.left[index].as_str()),
},
});
Expand All @@ -311,18 +310,18 @@ impl Dictionary {
Some(right_string) => right_string,
None => {
return Err(ReadError::Broken {
line: line_counter,
line: line_counter,
left_string: String::from(left_string),
reason: BrokenReason::NoRightString,
reason: BrokenReason::NoRightString,
})
}
},
};

if tokenizer.next().is_some() {
return Err(ReadError::Broken {
line: line_counter,
line: line_counter,
left_string: String::from(left_string),
reason: BrokenReason::BadRightString {
reason: BrokenReason::BadRightString {
right_string: String::from(right_string),
},
});
Expand All @@ -333,9 +332,9 @@ impl Dictionary {
for s in right_string.split("-->").map(|s| s.trim()) {
if s.is_empty() {
return Err(ReadError::Broken {
line: line_counter,
line: line_counter,
left_string: String::from(left_string),
reason: BrokenReason::BadRightString {
reason: BrokenReason::BadRightString {
right_string: String::from(right_string),
},
});
Expand Down
3 changes: 1 addition & 2 deletions word-dictionary/tests/tests.rs
@@ -1,5 +1,4 @@
use std::fs;
use std::path::Path;
use std::{fs, path::Path};

use word_dictionary::*;

Expand Down
1 change: 1 addition & 0 deletions words-transformer/Cargo.toml
Expand Up @@ -3,6 +3,7 @@ name = "words-transformer"
version = "0.1.0"
authors = ["Magic Len <len@magiclen.org>"]
edition = "2021"
rust-version = "1.61"
publish = false

[dependencies]
Expand Down

0 comments on commit b6c819c

Please sign in to comment.