pub struct BooleanAttribute { /* private fields */ }Implementations§
Source§impl BooleanAttribute
impl BooleanAttribute
Sourcepub fn new(name: CheetahString, changeable: bool, default_value: bool) -> Self
pub fn new(name: CheetahString, changeable: bool, default_value: bool) -> Self
Create a new boolean attribute with the specified properties
§Arguments
name- The name of the attributechangeable- Whether the attribute can be changed after creationdefault_value- Default boolean value for this attribute
§Returns
A new BooleanAttribute instance
§Example
use cheetah_string::CheetahString;
use rocketmq_model::common::attribute::bool_attribute::BooleanAttribute;
use rocketmq_model::common::attribute::Attribute;
let attr = BooleanAttribute::new(
CheetahString::from_static_str("enabled"),
true,
false
);
assert_eq!(attr.default_value(), false);
// Verify accepts valid boolean strings
assert!(attr.verify("true").is_ok());
assert!(attr.verify("FALSE").is_ok());Sourcepub fn default_value(&self) -> bool
pub fn default_value(&self) -> bool
Get the default value for this attribute
Sourcepub fn parse_bool(value: &str) -> Result<bool, String>
pub fn parse_bool(value: &str) -> Result<bool, String>
Parse a string value to boolean
Accepts “true” or “false” case-insensitively. Whitespace is not trimmed.
§Arguments
value- The string value to parse
§Returns
Ok(bool)- The parsed boolean valueErr(String)- An error message if the value is not “true” or “false”
§Errors
Returns an error if the input string is not “true” or “false” (case-insensitive).
§Example
use rocketmq_model::common::attribute::bool_attribute::BooleanAttribute;
// Case-insensitive parsing
assert_eq!(BooleanAttribute::parse_bool("true").unwrap(), true);
assert_eq!(BooleanAttribute::parse_bool("TRUE").unwrap(), true);
assert_eq!(BooleanAttribute::parse_bool("False").unwrap(), false);
// Invalid values return errors
assert!(BooleanAttribute::parse_bool("yes").is_err());
assert!(BooleanAttribute::parse_bool(" true").is_err()); // whitespace not trimmedTrait Implementations§
Source§impl Attribute for BooleanAttribute
impl Attribute for BooleanAttribute
Source§fn verify(&self, value: &str) -> Result<(), String>
fn verify(&self, value: &str) -> Result<(), String>
Verify that the provided string value is valid for this attribute.
Implementations should validate according to their specific rules.
Source§fn name(&self) -> &CheetahString
fn name(&self) -> &CheetahString
Get the name of this attribute.
Source§fn is_changeable(&self) -> bool
fn is_changeable(&self) -> bool
Check if this attribute can be changed after creation.
Source§impl Clone for BooleanAttribute
impl Clone for BooleanAttribute
Auto Trait Implementations§
impl Freeze for BooleanAttribute
impl RefUnwindSafe for BooleanAttribute
impl Send for BooleanAttribute
impl Sync for BooleanAttribute
impl Unpin for BooleanAttribute
impl UnsafeUnpin for BooleanAttribute
impl UnwindSafe for BooleanAttribute
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