Skip to content

Commit

Permalink
chore: accept pointers rather than values for the validate_nnn() func…
Browse files Browse the repository at this point in the history
…tions (#12)
  • Loading branch information
TrueBrain authored Apr 26, 2024
1 parent 142f711 commit e19c942
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod validate;
#[wasm_bindgen]
pub fn validate_base(js_config: JsValue, base: String) -> JsValue {
let config: validate::LanguageConfig = serde_wasm_bindgen::from_value(js_config).unwrap();
let response = validate::validate_base(config, base);
let response = validate::validate_base(&config, &base);
serde_wasm_bindgen::to_value(&response).unwrap()
}

Expand All @@ -20,7 +20,7 @@ pub fn validate_translation(
translation: String,
) -> JsValue {
let config: validate::LanguageConfig = serde_wasm_bindgen::from_value(js_config).unwrap();
let response = validate::validate_translation(config, base, case, translation);
let response = validate::validate_translation(&config, &base, &case, &translation);
serde_wasm_bindgen::to_value(&response).unwrap()
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ fn main() {

let result = match args.translation {
Some(translation) => validate::validate_translation(
config,
args.base,
args.case.unwrap_or(String::from("default")),
translation,
&config,
&args.base,
&args.case.unwrap_or(String::from("default")),
&translation,
),
None => validate::validate_base(config, args.base),
None => validate::validate_base(&config, &args.base),
};

for err in &result.errors {
Expand Down
10 changes: 5 additions & 5 deletions src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Serialize for Severity {
*
* @returns A normalized form of the base string for translators, and a list of error messages, if the base is invalid.
*/
pub fn validate_base(config: LanguageConfig, base: String) -> ValidationResult {
pub fn validate_base(config: &LanguageConfig, base: &String) -> ValidationResult {
let mut base = match ParsedString::parse(&base) {
Err(err) => {
return ValidationResult {
Expand Down Expand Up @@ -109,10 +109,10 @@ pub fn validate_base(config: LanguageConfig, base: String) -> ValidationResult {
* @returns A normalized form of the translation, and a list of error messages, if the translation is invalid.
*/
pub fn validate_translation(
config: LanguageConfig,
base: String,
case: String,
translation: String,
config: &LanguageConfig,
base: &String,
case: &String,
translation: &String,
) -> ValidationResult {
let base = match ParsedString::parse(&base) {
Err(_) => {
Expand Down

0 comments on commit e19c942

Please sign in to comment.