Skip to content

Commit

Permalink
♻️ Remove impl From in exchange for Phonotactic.to_rule() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaza-Kun committed Apr 16, 2024
1 parent 17db0a1 commit d4b8f91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
10 changes: 2 additions & 8 deletions wasm-rs/src/imbuhan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use onc::phonotactics::PhonotacticRule;

use std::collections::HashMap;

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -60,9 +58,7 @@ impl Imbuhan {
awal: Some(a),
akhir: _,
}) => {
if let Ok((_rest, phrase)) =
PhonotacticRule::from(phonotactic.clone()).parse_syllables(&text)
{
if let Ok((_rest, phrase)) = phonotactic.as_rule().parse_syllables(&text) {
if let Some(first) = phrase.syllables.first() {
let mut offset = 0;
let default = &"".to_string();
Expand Down Expand Up @@ -94,9 +90,7 @@ impl Imbuhan {
akhir: Some(a),
awal: _,
}) => {
if let Ok((_rest, phrase)) =
PhonotacticRule::from(phonotactic.clone()).parse_syllables(&text)
{
if let Ok((_rest, phrase)) = phonotactic.as_rule().parse_syllables(&text) {
if let Some(first) = phrase.syllables.first() {
let mut offset = 0;
let default = &"".to_string();
Expand Down
17 changes: 11 additions & 6 deletions wasm-rs/src/phonotactics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ pub struct Phonotactic {
definition: SyllableTags<String>,
}

impl From<Phonotactic> for PhonotacticRule {
fn from(value: Phonotactic) -> Self {
PhonotacticRule::with_definitions(value.definition)
}
}
// impl From<Phonotactic> for PhonotacticRule {
// fn from(value: Phonotactic) -> Self {
// PhonotacticRule::with_definitions(value.definition)
// }
// }

#[wasm_bindgen]
impl Phonotactic {
pub fn parse_string(&mut self, input: String, options: ParseResultOptions) -> ParseResults {
let text = input.to_lowercase();
let rule = PhonotacticRule::from(self.clone());
let rule = self.as_rule();
let s = rule.parse_syllables(&text);
InnerParseResult::from(s).render(options)
}

pub(crate) fn as_rule(&self) -> PhonotacticRule {
PhonotacticRule::with_definitions(self.definition.clone())
}

#[wasm_bindgen(getter)]
pub fn name(&self) -> String {
self.name.clone()
Expand Down

0 comments on commit d4b8f91

Please sign in to comment.