Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Mar 4, 2025
1 parent 8be3fac commit a86ecaa
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
2 changes: 1 addition & 1 deletion js-rattler/crate/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod error;
mod gateway;
mod parse_strictness;
pub mod solve;
mod utils;
mod version;
mod version_spec;
mod parse_strictness;

pub use error::{JsError, JsResult};

Expand Down
74 changes: 37 additions & 37 deletions js-rattler/crate/parse_strictness.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
use serde::Deserialize;
use wasm_bindgen::prelude::wasm_bindgen;
use rattler_conda_types::ParseStrictness;

#[wasm_bindgen(typescript_custom_section)]
const PARSE_STRICTNESS_TS: &'static str = r#"
/**
* Defines how strict a parser should be when parsing an object from a string.
*
* @public
*/
export type ParseStrictness = "strict" | "lenient";
"#;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name="ParseStrictness", typescript_type = "ParseStrictness")]
pub type JsParseStrictness;
}

impl TryFrom<JsParseStrictness> for ParseStrictness {
type Error = serde_wasm_bindgen::Error;

fn try_from(value: JsParseStrictness) -> Result<Self, Self::Error> {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum EnumNames {
Strict,
Lenient,
}

match serde_wasm_bindgen::from_value(value.obj)? {
EnumNames::Strict => Ok(ParseStrictness::Strict),
EnumNames::Lenient => Ok(ParseStrictness::Lenient),
}
}
}
use rattler_conda_types::ParseStrictness;
use serde::Deserialize;
use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen(typescript_custom_section)]
const PARSE_STRICTNESS_TS: &'static str = r#"
/**
* Defines how strict a parser should be when parsing an object from a string.
*
* @public
*/
export type ParseStrictness = "strict" | "lenient";
"#;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_name = "ParseStrictness", typescript_type = "ParseStrictness")]
pub type JsParseStrictness;
}

impl TryFrom<JsParseStrictness> for ParseStrictness {
type Error = serde_wasm_bindgen::Error;

fn try_from(value: JsParseStrictness) -> Result<Self, Self::Error> {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum EnumNames {
Strict,
Lenient,
}

match serde_wasm_bindgen::from_value(value.obj)? {
EnumNames::Strict => Ok(ParseStrictness::Strict),
EnumNames::Lenient => Ok(ParseStrictness::Lenient),
}
}
}
14 changes: 10 additions & 4 deletions js-rattler/crate/version.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{cmp::Ordering, str::FromStr};
use wasm_bindgen::JsValue;
use rattler_conda_types::{Version, VersionBumpType};
use std::{cmp::Ordering, str::FromStr};
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;

use crate::JsResult;

Expand Down Expand Up @@ -85,10 +85,16 @@ impl JsVersion {
/// represent a typical major minor version. If any of the parts are not a
/// single number, undefined is returned.
// TODO: Simplify when https://github.com/rustwasm/wasm-bindgen/issues/122 is fixed
#[wasm_bindgen(js_name = "asMajorMinor", unchecked_return_type="[number, number] | undefined")]
#[wasm_bindgen(
js_name = "asMajorMinor",
unchecked_return_type = "[number, number] | undefined"
)]
pub fn as_major_minor(&self) -> Option<Vec<JsValue>> {
let (major, minor) = self.as_ref().as_major_minor()?;
Some(vec![JsValue::from(major as usize), JsValue::from(minor as usize)])
Some(vec![
JsValue::from(major as usize),
JsValue::from(minor as usize),
])
}

/// Returns true if this version starts with the other version. This is
Expand Down
8 changes: 3 additions & 5 deletions js-rattler/crate/version_spec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use rattler_conda_types::{ParseStrictness, VersionSpec};
use wasm_bindgen::{prelude::wasm_bindgen};
use wasm_bindgen::prelude::wasm_bindgen;

use crate::{version::JsVersion, JsResult};
use crate::parse_strictness::JsParseStrictness;
use crate::{version::JsVersion, JsResult};

/// Represents a version specification in the conda ecosystem.
///
Expand Down Expand Up @@ -39,9 +39,7 @@ impl JsVersionSpec {
pub fn new(
#[wasm_bindgen(param_description = "The string representation of the version spec.")]
version_spec: &str,
#[wasm_bindgen(
param_description = "The strictness of the parser.",
)]
#[wasm_bindgen(param_description = "The strictness of the parser.")]
parse_strictness: Option<JsParseStrictness>,
) -> JsResult<Self> {
let parse_strictness = parse_strictness
Expand Down
2 changes: 1 addition & 1 deletion js-rattler/src/Version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { Version } from "../pkg"
export { Version } from "../pkg";

0 comments on commit a86ecaa

Please sign in to comment.