pub enum BpsvValue {
String(String),
Hex(String),
Decimal(i64),
Empty,
}Expand description
Represents a typed value in a BPSV document
Variants§
String(String)
String value
Hex(String)
Hexadecimal value (stored as lowercase string)
Decimal(i64)
Decimal integer value
Empty
Empty/null value
Implementations§
Source§impl BpsvValue
impl BpsvValue
Sourcepub fn parse(value: &str, field_type: &BpsvFieldType) -> Result<Self>
pub fn parse(value: &str, field_type: &BpsvFieldType) -> Result<Self>
Parse a string value according to the specified field type
§Examples
use ngdp_bpsv::{BpsvValue, BpsvFieldType};
let string_val = BpsvValue::parse("hello", &BpsvFieldType::String(0))?;
assert_eq!(string_val, BpsvValue::String("hello".to_string()));
let hex_val = BpsvValue::parse("ABCD1234", &BpsvFieldType::Hex(4))?;
assert_eq!(hex_val, BpsvValue::Hex("abcd1234".to_string()));
let dec_val = BpsvValue::parse("1234", &BpsvFieldType::Decimal(4))?;
assert_eq!(dec_val, BpsvValue::Decimal(1234));
let empty_val = BpsvValue::parse("", &BpsvFieldType::String(0))?;
assert_eq!(empty_val, BpsvValue::Empty);Sourcepub fn to_bpsv_string(&self) -> String
pub fn to_bpsv_string(&self) -> String
Convert the value to its string representation for BPSV output
Sourcepub fn as_decimal(&self) -> Option<i64>
pub fn as_decimal(&self) -> Option<i64>
Get the value as a decimal number, if it is a decimal type
Sourcepub fn into_string(self) -> Option<String>
pub fn into_string(self) -> Option<String>
Convert to string value, consuming self
Sourcepub fn into_decimal(self) -> Option<i64>
pub fn into_decimal(self) -> Option<i64>
Convert to decimal value, consuming self
Sourcepub fn value_type(&self) -> &'static str
pub fn value_type(&self) -> &'static str
Get the type of this value
Sourcepub fn is_compatible_with(&self, field_type: &BpsvFieldType) -> bool
pub fn is_compatible_with(&self, field_type: &BpsvFieldType) -> bool
Check if this value is compatible with the given field type
Trait Implementations§
impl StructuralPartialEq for BpsvValue
Auto Trait Implementations§
impl Freeze for BpsvValue
impl RefUnwindSafe for BpsvValue
impl Send for BpsvValue
impl Sync for BpsvValue
impl Unpin for BpsvValue
impl UnwindSafe for BpsvValue
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