pub struct Properties { /* private fields */ }
Expand description
A wrapper around serde_json::Value
for properties-style configuration data.
This struct provides a type-safe interface for working with properties configuration data retrieved from Apollo. Properties are typically stored as key-value pairs where all values are strings that can be parsed into various types.
§Thread Safety
This struct is Clone
and Debug
, making it easy to work with in concurrent
environments. The underlying serde_json::Value
is also thread-safe.
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({
"database.host": "localhost",
"database.port": "5432",
"database.ssl": "true"
});
let properties = Properties::from(props_data);
Implementations§
Source§impl Properties
impl Properties
Sourcepub fn get_property<T: FromStr>(&self, key: &str) -> Option<T>
pub fn get_property<T: FromStr>(&self, key: &str) -> Option<T>
Gets a property value and attempts to parse it into the specified type.
This is a generic method that can parse string values into any type that
implements FromStr
. It first retrieves the value as a string, then
attempts to parse it into the target type.
§Type Parameters
T
- The target type to parse into. Must implementstd::str::FromStr
.
§Arguments
key
- The property key to retrieve
§Returns
Some(T)
- The parsed value if the key exists and parsing succeedsNone
- If the key doesn’t exist, the value is not a string, or parsing fails
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({"timeout": "30", "retries": "3"});
let properties = Properties::from(props_data);
let timeout: Option<u32> = properties.get_property("timeout");
let retries: Option<i32> = properties.get_property("retries");
Source§impl Properties
impl Properties
Sourcepub fn get_string(&self, key: &str) -> Option<String>
pub fn get_string(&self, key: &str) -> Option<String>
Get a property from the cache as a string.
This method retrieves a property value and returns it as a String
.
It’s a convenience method that wraps get_property::<String>()
.
§Arguments
key
- The key to get the property for.
§Returns
Some(String)
- The property value as a string if it existsNone
- If the key doesn’t exist or the value cannot be converted to a string
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({"app.name": "MyApp"});
let properties = Properties::from(props_data);
let app_name = properties.get_string("app.name");
assert_eq!(app_name, Some("MyApp".to_string()));
Sourcepub fn get_int(&self, key: &str) -> Option<i64>
pub fn get_int(&self, key: &str) -> Option<i64>
Get a property from the cache as an integer.
This method retrieves a property value and attempts to parse it as an i64
.
It’s a convenience method that wraps get_property::<i64>()
.
§Arguments
key
- The key to get the property for.
§Returns
Some(i64)
- The property value as an integer if it exists and can be parsedNone
- If the key doesn’t exist or the value cannot be parsed as an integer
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({"server.port": "8080"});
let properties = Properties::from(props_data);
let port = properties.get_int("server.port");
assert_eq!(port, Some(8080));
Sourcepub fn get_float(&self, key: &str) -> Option<f64>
pub fn get_float(&self, key: &str) -> Option<f64>
Get a property from the cache as a float.
This method retrieves a property value and attempts to parse it as an f64
.
It’s a convenience method that wraps get_property::<f64>()
.
§Arguments
key
- The key to get the property for.
§Returns
Some(f64)
- The property value as a float if it exists and can be parsedNone
- If the key doesn’t exist or the value cannot be parsed as a float
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({"timeout.seconds": "30.5"});
let properties = Properties::from(props_data);
let timeout = properties.get_float("timeout.seconds");
assert_eq!(timeout, Some(30.5));
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Get a property from the cache as a boolean.
This method retrieves a property value and attempts to parse it as a bool
.
It’s a convenience method that wraps get_property::<bool>()
. The parsing
follows Rust’s standard boolean parsing rules (accepts “true”/“false”).
§Arguments
key
- The key to get the property for.
§Returns
Some(bool)
- The property value as a boolean if it exists and can be parsedNone
- If the key doesn’t exist or the value cannot be parsed as a boolean
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({"debug.enabled": "true"});
let properties = Properties::from(props_data);
let debug_enabled = properties.get_bool("debug.enabled");
assert_eq!(debug_enabled, Some(true));
Trait Implementations§
Source§impl Clone for Properties
impl Clone for Properties
Source§fn clone(&self) -> Properties
fn clone(&self) -> Properties
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Properties
impl Debug for Properties
Source§impl From<Properties> for JsValue
impl From<Properties> for JsValue
Source§fn from(value: Properties) -> Self
fn from(value: Properties) -> Self
Source§impl From<Value> for Properties
Converts a serde_json::Value
into a Properties
instance.
impl From<Value> for Properties
Converts a serde_json::Value
into a Properties
instance.
This implementation allows for easy creation of Properties
instances from
raw JSON data, typically used by the namespace detection system. The JSON
value is expected to be an object where keys are property names and values
are the property values (typically strings).
§Examples
use serde_json::json;
use apollo_client::namespace::properties::Properties;
let props_data = json!({
"app.name": "MyApp",
"app.version": "1.0.0"
});
let properties = Properties::from(props_data);
Source§impl FromWasmAbi for Properties
impl FromWasmAbi for Properties
Source§impl IntoWasmAbi for Properties
impl IntoWasmAbi for Properties
Source§impl LongRefFromWasmAbi for Properties
impl LongRefFromWasmAbi for Properties
Source§impl OptionFromWasmAbi for Properties
impl OptionFromWasmAbi for Properties
Source§impl OptionIntoWasmAbi for Properties
impl OptionIntoWasmAbi for Properties
Source§impl RefFromWasmAbi for Properties
impl RefFromWasmAbi for Properties
Source§type Anchor = RcRef<Properties>
type Anchor = RcRef<Properties>
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl RefMutFromWasmAbi for Properties
impl RefMutFromWasmAbi for Properties
Source§impl TryFromJsValue for Properties
impl TryFromJsValue for Properties
Source§impl VectorFromWasmAbi for Properties
impl VectorFromWasmAbi for Properties
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Properties]>
Source§impl VectorIntoJsValue for Properties
impl VectorIntoJsValue for Properties
fn vector_into_jsvalue(vector: Box<[Properties]>) -> JsValue
Source§impl VectorIntoWasmAbi for Properties
impl VectorIntoWasmAbi for Properties
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[Properties]>) -> Self::Abi
Source§impl WasmDescribeVector for Properties
impl WasmDescribeVector for Properties
impl SupportsConstructor for Properties
impl SupportsInstanceProperty for Properties
impl SupportsStaticProperty for Properties
Auto Trait Implementations§
impl Freeze for Properties
impl RefUnwindSafe for Properties
impl Send for Properties
impl Sync for Properties
impl Unpin for Properties
impl UnwindSafe for Properties
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
Source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.