Skip to content

Commit

Permalink
rename dimension_entry_type -> base_dimension_type, rename inner meth…
Browse files Browse the repository at this point in the history
…ods to be more descriptive
  • Loading branch information
Tehforsch committed Dec 31, 2023
1 parent a1f0167 commit 51d2c7a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ impl Defs {
quote! { Ratio }
}

pub fn zero(&self, ident: &Ident) -> TokenStream {
pub fn zero_entry(&self, ident: &Ident) -> TokenStream {
quote! { #ident: Ratio::int(0), }
}

pub fn add(&self, ident: &Ident) -> TokenStream {
pub fn add_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.add(other.#ident),
}
}

pub fn sub(&self, ident: &Ident) -> TokenStream {
pub fn sub_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.sub(other.#ident),
}
}

pub fn neg(&self, ident: &Ident) -> TokenStream {
pub fn neg_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.neg(),
}
}

pub fn mul(&self, ident: &Ident) -> TokenStream {
pub fn mul_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.mul(Ratio::int(other)),
}
}

pub fn sqrt(&self, ident: &Ident) -> TokenStream {
pub fn sqrt_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.div(Ratio::int(2)),
}
}

pub fn cbrt(&self, ident: &Ident) -> TokenStream {
pub fn cbrt_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident.div(Ratio::int(3)),
}
Expand All @@ -72,41 +72,41 @@ impl Defs {
quote! { i32 }
}

pub fn zero(&self, ident: &Ident) -> TokenStream {
pub fn zero_entry(&self, ident: &Ident) -> TokenStream {
quote! { #ident: 0, }
}

pub fn add(&self, ident: &Ident) -> TokenStream {
pub fn add_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident + other.#ident,
}
}

pub fn sub(&self, ident: &Ident) -> TokenStream {
pub fn sub_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident - other.#ident,
}
}

pub fn neg(&self, ident: &Ident) -> TokenStream {
pub fn neg_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: -self.#ident,
}
}

pub fn mul(&self, ident: &Ident) -> TokenStream {
pub fn mul_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident * other,
}
}

pub fn sqrt(&self, ident: &Ident) -> TokenStream {
pub fn sqrt_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident / 2,
}
}

pub fn cbrt(&self, ident: &Ident) -> TokenStream {
pub fn cbrt_entry(&self, ident: &Ident) -> TokenStream {
quote! {
#ident: self.#ident / 3,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/diman_unit_system/src/codegen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod base_dimension_type;
mod debug;
mod dimension_entry_type;
mod float_methods;
mod generic_methods;
#[cfg(feature = "hdf5")]
Expand Down
14 changes: 7 additions & 7 deletions crates/diman_unit_system/src/derive_dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,37 @@ impl Defs {
let type_name = &self.dimension_type;
let none_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.zero(ident))
.map(|ident| self.zero_entry(ident))
.collect();

let mul_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.add(ident))
.map(|ident| self.add_entry(ident))
.collect();

let div_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.sub(ident))
.map(|ident| self.sub_entry(ident))
.collect();

let inv_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.neg(ident))
.map(|ident| self.neg_entry(ident))
.collect();

let powi_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.mul(ident))
.map(|ident| self.mul_entry(ident))
.collect();

let sqrt_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.sqrt(ident))
.map(|ident| self.sqrt_entry(ident))
.collect();

let cbrt_gen: proc_macro2::TokenStream = self
.base_dimensions()
.map(|ident| self.cbrt(ident))
.map(|ident| self.cbrt_entry(ident))
.collect();

let sqrt_safety_gen: proc_macro2::TokenStream = self
Expand Down

0 comments on commit 51d2c7a

Please sign in to comment.