pub struct WafObject { /* private fields */ }
Expand description
The low-level representation of an arbitrary WAF object.
It is usually converted to a TypedWafObject
by calling WafObject::as_type
.
Implementations§
Source§impl WafObject
impl WafObject
Sourcepub fn from_json(json: impl AsRef<[u8]>) -> Option<WafOwned<Self>>
pub fn from_json(json: impl AsRef<[u8]>) -> Option<WafOwned<Self>>
Creates a new WafObject
from a JSON string.
This function is not intended to be used with un-trusted/adversarial
input. The typical use-case is to facilitate parsing rulesets for use
with crate::builder::Builder::add_or_update_config
.
§Returns
Returns None
if parsing the JSON string into a WafObject
was not
possible, or if the input JSON string is larger than u32::MAX
bytes.
Sourcepub fn get_type(&self) -> WafObjectType
pub fn get_type(&self) -> WafObjectType
Returns the WafObjectType
of the underlying value.
Returns WafObjectType::Invalid
if the underlying value’s type is not set to a
known, valid WafObjectType
value.
Sourcepub fn as_type<T: TypedWafObject>(&self) -> Option<&T>
pub fn as_type<T: TypedWafObject>(&self) -> Option<&T>
Returns a reference to this value as a T
if its type corresponds.
Sourcepub fn as_type_mut<T: TypedWafObject>(&mut self) -> Option<&mut T>
pub fn as_type_mut<T: TypedWafObject>(&mut self) -> Option<&mut T>
Returns a mutable reference to this value as a T
if its type corresponds.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Returns true if this WafObject
is not WafObjectType::Invalid
, meaning it can be
converted to one of the TypedWafObject
implementations.
Sourcepub fn to_u64(&self) -> Option<u64>
pub fn to_u64(&self) -> Option<u64>
Returns the value of this WafObject
as a u64
if its type is WafObjectType::Unsigned
.
Sourcepub fn to_i64(&self) -> Option<i64>
pub fn to_i64(&self) -> Option<i64>
Returns the value of this WafObject
as a i64
if its type is WafObjectType::Signed
(or
WafObjectType::Unsigned
with a value that can be represented as an i64
).
Sourcepub fn to_f64(&self) -> Option<f64>
pub fn to_f64(&self) -> Option<f64>
Returns the value of this WafObject
as a f64
if its type is WafObjectType::Float
.