Properties

Struct Properties 

Source
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

Source

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 implement std::str::FromStr.
§Arguments
  • key - The property key to retrieve
§Returns
  • Some(T) - The parsed value if the key exists and parsing succeeds
  • None - 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

Source

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 exists
  • None - 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()));
Source

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 parsed
  • None - 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));
Source

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 parsed
  • None - 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));
Source

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 parsed
  • None - 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

Source§

fn clone(&self) -> Properties

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Properties

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Properties> for JsValue

Source§

fn from(value: Properties) -> Self

Converts to this type from the input type.
Source§

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§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for Properties

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for Properties

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for Properties

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<Properties>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for Properties

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for Properties

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for Properties

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<Properties>

The type that holds the reference to 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§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for Properties

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<Properties>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for Properties

Source§

type Error = JsValue

The type returned in the event of a conversion error.
Source§

fn try_from_js_value(value: JsValue) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl VectorFromWasmAbi for Properties

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[Properties]>

Source§

impl VectorIntoJsValue for Properties

Source§

impl VectorIntoWasmAbi for Properties

Source§

impl WasmDescribe for Properties

Source§

impl WasmDescribeVector for Properties

Source§

impl SupportsConstructor for Properties

Source§

impl SupportsInstanceProperty for Properties

Source§

impl SupportsStaticProperty for Properties

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,