Skip to main content

DecimalDataType

Struct DecimalDataType 

Source
pub struct DecimalDataType {
    pub precision: u8,
    pub scale: u8,
}
Expand description

Exact numeric type with fixed precision and scale.

Maps to: NUMERIC/DECIMAL (PostgreSQL, SQL Server), NUMBER (Snowflake), DECIMAL (Databricks), Decimal (ClickHouse).

§Constraints

  • precision: 1–38 (most databases), up to 76 (some platforms)
  • scale: 0 to precision
  • Panics if scale > precision or precision > 38

§Example

use razeri_plugin_contract::data_type::DecimalDataType;

// Money: DECIMAL(19, 4)
let money = DecimalDataType::money();
assert_eq!(money.precision, 19);
assert_eq!(money.scale, 4);

// Percentage: DECIMAL(5, 2)
let pct = DecimalDataType::percentage();
assert_eq!(pct.precision, 5);
assert_eq!(pct.scale, 2);

// Custom decimal
let custom = DecimalDataType::new(10, 2);
assert_eq!(custom.precision, 10);
assert_eq!(custom.scale, 2);

Fields§

§precision: u8

Total number of digits (1–38 for most databases, up to 76 for some).

§scale: u8

Number of digits after the decimal point (0 to precision).

Implementations§

Source§

impl DecimalDataType

Source

pub fn new(precision: u8, scale: u8) -> Self

Creates a new decimal type with the given precision and scale.

§Panics

Panics if precision is 0 or exceeds 38, or if scale > precision.

§Example
use razeri_plugin_contract::data_type::DecimalDataType;

let dec = DecimalDataType::new(10, 2);
assert_eq!(dec.precision, 10);
assert_eq!(dec.scale, 2);
§Panics
ⓘ
use razeri_plugin_contract::data_type::DecimalDataType;

// Precision must be 1-38
let _ = DecimalDataType::new(0, 0); // panics

// Scale cannot exceed precision
let _ = DecimalDataType::new(5, 10); // panics
Source

pub fn money() -> Self

Creates the common money type: DECIMAL(19, 4).

§Example
use razeri_plugin_contract::data_type::DecimalDataType;

let money = DecimalDataType::money();
assert_eq!(money.precision, 19);
assert_eq!(money.scale, 4);
Source

pub fn percentage() -> Self

Creates a percentage type with 2 decimal places: DECIMAL(5, 2).

§Example
use razeri_plugin_contract::data_type::DecimalDataType;

let pct = DecimalDataType::percentage();
assert_eq!(pct.precision, 5);
assert_eq!(pct.scale, 2);

Trait Implementations§

Source§

impl Clone for DecimalDataType

Source§

fn clone(&self) -> DecimalDataType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DecimalDataType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DecimalDataType

Source§

impl Hash for DecimalDataType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DecimalDataType

Source§

fn eq(&self, other: &DecimalDataType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DecimalDataType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.