pub struct Params(/* private fields */);Expand description
Immutable generic parameter storage.
This represents a map of string keys to JSON values, used for passing adapter-specific configuration, metadata, and any generic key-value data.
from_pydict rejects integer values outside the signed or unsigned 64-bit range with
ValueError, including values in nested containers.
Params uses IndexMap to preserve insertion order, which is important for
consistent serialization and debugging.
Maps built with Self::from_shared share storage across clones and can share values
across different maps. Self::get, Self::borrowed_entries, and the typed getters borrow
these values directly. len, is_empty, capacity, and contains_key also avoid copying.
Indexing, &Params iteration, and access through the read-only IndexMap interface
materialize and cache owned values. Use borrowed_entries to iterate without copying.
Serialization preserves contents and insertion order, but not allocation sharing.
Build an owned map before calling Self::new. To derive different
parameters, use IndexMap::clone(¶ms), edit the map, and construct a new Params.
To retain shared values, edit the map from Self::to_shared_map and call
Self::from_shared.
The compiler rejects mutation, including nested JSON values:
use nautilus_core::Params;
let mut params = Params::empty();
params.insert("key".to_string(), serde_json::json!(1));use nautilus_core::Params;
let mut params = Params::new(
[("nested".to_string(), serde_json::json!({"value": 1}))].into(),
);
params["nested"]["value"] = serde_json::json!(2);use nautilus_core::Params;
use std::sync::Arc;
let mut params = Params::from_shared(
[("nested".to_string(), Arc::new(serde_json::json!({"value": 1})))].into(),
);
params["nested"]["value"] = serde_json::json!(2);Implementations§
Source§impl Params
impl Params
Creates immutable parameters from shared JSON values without copying their contents.
Copies the map for deriving new parameters, retaining existing shared value allocations.
Owned values are cloned.
Sourcepub fn borrowed_entries(
&self,
) -> impl DoubleEndedIterator<Item = (&String, &Value)>
pub fn borrowed_entries( &self, ) -> impl DoubleEndedIterator<Item = (&String, &Value)>
Borrows entries in insertion order without materializing shared values.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<&Value>
pub fn get<Q>(&self, key: &Q) -> Option<&Value>
Returns a value by key without materializing shared values.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns whether the map contains a key.
Sourcepub fn estimated_heap_size(&self) -> usize
pub fn estimated_heap_size(&self) -> usize
Estimates retained key, value, and element storage without materializing shared values.
Charges shared values in full for each entry and includes any cached owned map. Excludes the outer storage allocation, allocator overhead, and hash-table overhead.
Sourcepub fn get_u64(&self, key: &str) -> Option<u64>
pub fn get_u64(&self, key: &str) -> Option<u64>
Extracts a u64 value from the params map.
Returns None if the key is missing or the value cannot be converted to u64.
Sourcepub fn get_i64(&self, key: &str) -> Option<i64>
pub fn get_i64(&self, key: &str) -> Option<i64>
Extracts an i64 value from the params map.
Returns None if the key is missing or the value cannot be converted to i64.
Sourcepub fn get_usize(&self, key: &str) -> Option<usize>
pub fn get_usize(&self, key: &str) -> Option<usize>
Extracts a usize value from the params map.
Returns None if the key is missing or the value cannot be converted to usize.
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
Extracts a string value from the params map.
Returns None if the key is missing or the value is not a string.
Sourcepub fn get_bool(&self, key: &str) -> Option<bool>
pub fn get_bool(&self, key: &str) -> Option<bool>
Extracts a boolean value from the params map.
Returns None if the key is missing or the value is not a boolean.
Methods from Deref<Target = IndexMap<String, Value>>§
pub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Return the number of elements the map can hold without reallocating.
This number is a lower bound; the map might be able to hold more, but is guaranteed to be able to hold at least this many.
Computes in O(1) time.
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Return an iterator over the key-value pairs of the map, in their order
pub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
Return an iterator over the values of the map, in their order
pub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Return true if an equivalent to key exists in the map.
Computes in O(1) time (average).
pub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get<Q>(&self, key: &Q) -> Option<&V>
Return a reference to the stored value for key, if it is present,
else None.
Computes in O(1) time (average).
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Return references to the stored key-value pair for the lookup key,
if it is present, else None.
Computes in O(1) time (average).
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, &K, &V)>
Return the index with references to the stored key-value pair for the
lookup key, if it is present, else None.
Computes in O(1) time (average).
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
Return the item index for key, if it is present, else None.
Computes in O(1) time (average).
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>where
K: Ord,
pub fn binary_search_keys(&self, x: &K) -> Result<usize, usize>where
K: Ord,
Search over a sorted map for a key.
Returns the position where that key is present, or the position where it can be inserted to
maintain the sort. See slice::binary_search for more details.
Computes in O(log(n)) time, which is notably less scalable than looking the key up
using [get_index_of][IndexMap::get_index_of], but this can also position missing keys.
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
Search over a sorted map with a comparator function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by for more details.
Computes in O(log(n)) time.
pub fn binary_search_by_key<'a, B, F>(
&'a self,
b: &B,
f: F,
) -> Result<usize, usize>
pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
Search over a sorted map with an extraction function.
Returns the position where that value is present, or the position where it can be inserted
to maintain the sort. See slice::binary_search_by_key for more details.
Computes in O(log(n)) time.
pub fn is_sorted(&self) -> boolwhere
K: PartialOrd,
pub fn is_sorted(&self) -> boolwhere
K: PartialOrd,
Checks if the keys of this map are sorted.
pub fn is_sorted_by<'a, F>(&'a self, cmp: F) -> bool
pub fn is_sorted_by<'a, F>(&'a self, cmp: F) -> bool
Checks if this map is sorted using the given comparator function.
pub fn is_sorted_by_key<'a, F, T>(&'a self, sort_key: F) -> bool
pub fn is_sorted_by_key<'a, F, T>(&'a self, sort_key: F) -> bool
Checks if this map is sorted using the given sort-key function.
pub fn partition_point<P>(&self, pred: P) -> usize
pub fn partition_point<P>(&self, pred: P) -> usize
Returns the index of the partition point of a sorted map according to the given predicate (the index of the first element of the second partition).
See slice::partition_point for more details.
Computes in O(log(n)) time.
pub fn as_slice(&self) -> &Slice<K, V>
pub fn as_slice(&self) -> &Slice<K, V>
Returns a slice of all the key-value pairs in the map.
Computes in O(1) time.
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
Get a key-value pair by index
Valid indices are 0 <= index < self.len().
Computes in O(1) time.
pub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
pub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
Returns a slice of key-value pairs in the given range of indices.
Valid indices are 0 <= index < self.len().
Computes in O(1) time.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Params
impl<'de> Deserialize<'de> for Params
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Params
Source§impl<'a> IntoIterator for &'a Params
impl<'a> IntoIterator for &'a Params
Auto Trait Implementations§
impl Freeze for Params
impl RefUnwindSafe for Params
impl Send for Params
impl Sync for Params
impl Unpin for Params
impl UnsafeUnpin for Params
impl UnwindSafe for Params
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.