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 toprecision- Panics if
scale > precisionorprecision > 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: u8Total number of digits (1–38 for most databases, up to 76 for some).
scale: u8Number of digits after the decimal point (0 to precision).
Implementations§
Source§impl DecimalDataType
impl DecimalDataType
Sourcepub fn new(precision: u8, scale: u8) -> Self
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); // panicsSourcepub fn money() -> Self
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);Sourcepub fn percentage() -> Self
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
impl Clone for DecimalDataType
Source§impl Debug for DecimalDataType
impl Debug for DecimalDataType
impl Eq for DecimalDataType
Source§impl Hash for DecimalDataType
impl Hash for DecimalDataType
Source§impl PartialEq for DecimalDataType
impl PartialEq for DecimalDataType
impl StructuralPartialEq for DecimalDataType
Auto Trait Implementations§
impl Forget for DecimalDataType
impl Freeze for DecimalDataType
impl Move for DecimalDataType
impl RefUnwindSafe for DecimalDataType
impl Send for DecimalDataType
impl Sync for DecimalDataType
impl Unpin for DecimalDataType
impl UnsafeUnpin for DecimalDataType
impl UnwindSafe for DecimalDataType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more