summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs56
1 files changed, 18 insertions, 38 deletions
diff --git a/src/lib.rs b/src/lib.rs
index aed8536..3483847 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -556,23 +556,15 @@ extern "C" fn parser_parse(
fn read_label(label: *mut std::os::raw::c_uchar) -> ForestLabel<GrammarLabel> {
let status: u8 = unsafe { *label };
- let label_status: ForestLabelType;
-
- match status {
- 0 => {
- label_status = ForestLabelType::Plain;
- }
- 1 => {
- label_status = ForestLabelType::Packed;
- }
- _ => {
- label_status = ForestLabelType::Cloned(usize::from_be_bytes(
- unsafe { std::slice::from_raw_parts(label.add(1), 8) }
- .try_into()
- .unwrap(),
- ));
- }
- }
+ let label_status: ForestLabelType = match status {
+ 0 => ForestLabelType::Plain,
+ 1 => ForestLabelType::Packed,
+ _ => ForestLabelType::Cloned(usize::from_be_bytes(
+ unsafe { std::slice::from_raw_parts(label.add(1), 8) }
+ .try_into()
+ .unwrap(),
+ )),
+ };
let start = usize::from_be_bytes(
unsafe { std::slice::from_raw_parts(label.add(9), 8) }
@@ -594,19 +586,11 @@ fn read_label(label: *mut std::os::raw::c_uchar) -> ForestLabel<GrammarLabel> {
.unwrap(),
);
- let inner_label: GrammarLabel;
-
- match discriminant {
- 0 => {
- inner_label = GrammarLabel::new_closed(TNT::Ter(content), start, end);
- }
- 1 => {
- inner_label = GrammarLabel::new_closed(TNT::Non(content), start, end);
- }
- _ => {
- inner_label = GrammarLabel::new_closed(content, start, end);
- }
- }
+ let inner_label: GrammarLabel = match discriminant {
+ 0 => GrammarLabel::new_closed(TNT::Ter(content), start, end),
+ 1 => GrammarLabel::new_closed(TNT::Non(content), start, end),
+ _ => GrammarLabel::new_closed(content, start, end),
+ };
ForestLabel::new(inner_label, label_status)
}
@@ -667,7 +651,7 @@ extern "C" fn print_forest(
let special_marks = unsafe { std::slice::from_raw_parts((*forest_vec).data.add(8), 3) };
- if special_marks != &[114, 101, 112] {
+ if special_marks != [114, 101, 112] {
return_error!(
format!(
"the forest does not begin with the special mark\nThe first bytes are: \
@@ -785,16 +769,12 @@ extern "C" fn print_forest(
let result = format!("{preamble}{post}");
- let parsed_filename;
-
- match unsafe { std::ffi::CStr::from_ptr(filename).to_str() } {
- Ok(ccstr) => {
- parsed_filename = ccstr;
- }
+ let parsed_filename = match unsafe { std::ffi::CStr::from_ptr(filename).to_str() } {
+ Ok(ccstr) => ccstr,
Err(e) => {
return_error!(format!("error: {e}"), error_len, error_cap, error_vec);
}
- }
+ };
if std::fs::metadata(parsed_filename).is_ok() {
let _ = std::fs::remove_file(parsed_filename);