Skip to main content

Params

Struct Params 

Source
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(&params), 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

Source

pub fn empty() -> Self

Creates an empty Params map.

Source

pub fn new(map: IndexMap<String, Value>) -> Self

Creates Params from an IndexMap.

Source

pub fn from_shared(map: IndexMap<String, Arc<Value>>) -> Self

Creates immutable parameters from shared JSON values without copying their contents.

Source

pub fn to_shared_map(&self) -> IndexMap<String, Arc<Value>>

Copies the map for deriving new parameters, retaining existing shared value allocations.

Owned values are cloned.

Source

pub fn borrowed_entries( &self, ) -> impl DoubleEndedIterator<Item = (&String, &Value)>

Borrows entries in insertion order without materializing shared values.

Source

pub fn len(&self) -> usize

Returns the number of parameters.

Source

pub fn is_empty(&self) -> bool

Returns whether the map is empty.

Source

pub fn capacity(&self) -> usize

Returns the map capacity without materializing shared values.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&Value>
where Q: ?Sized + Hash + Equivalent<String>,

Returns a value by key without materializing shared values.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: ?Sized + Hash + Equivalent<String>,

Returns whether the map contains a key.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_f64(&self, key: &str) -> Option<f64>

Extracts a f64 value from the params map.

Returns None if the key is missing or the value cannot be converted to f64.

Source

pub fn to_pydict(&self, py: Python<'_>) -> PyResult<Py<PyDict>>

Converts Params to a Python dict.

§Errors

Returns an error if conversion of any value fails.

Methods from Deref<Target = IndexMap<String, Value>>§

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 hasher(&self) -> &S

Return a reference to the map’s BuildHasher.

pub fn len(&self) -> usize

Return the number of key-value pairs in the map.

Computes in O(1) time.

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Computes in O(1) time.

pub fn iter(&self) -> Iter<'_, K, V> ⓘ

Return an iterator over the key-value pairs of the map, in their order

pub fn keys(&self) -> Keys<'_, K, V> ⓘ

Return an iterator over the keys of the map, in their order

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
where Q: Hash + Equivalent<K> + ?Sized,

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>
where Q: Hash + Equivalent<K> + ?Sized,

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)>
where Q: Hash + Equivalent<K> + ?Sized,

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)>
where Q: Hash + Equivalent<K> + ?Sized,

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>
where Q: Hash + Equivalent<K> + ?Sized,

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,

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>
where F: FnMut(&'a K, &'a V) -> Ordering,

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>
where F: FnMut(&'a K, &'a V) -> B, B: Ord,

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) -> bool
where K: PartialOrd,

Checks if the keys of this map are sorted.

pub fn is_sorted_by<'a, F>(&'a self, cmp: F) -> bool
where F: FnMut(&'a K, &'a V, &'a K, &'a V) -> 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
where F: FnMut(&'a K, &'a V) -> T, T: PartialOrd,

Checks if this map is sorted using the given sort-key function.

pub fn partition_point<P>(&self, pred: P) -> usize
where P: FnMut(&K, &V) -> bool,

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>

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)>

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>,

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.

pub fn first(&self) -> Option<(&K, &V)>

Get the first key-value pair

Computes in O(1) time.

pub fn last(&self) -> Option<(&K, &V)>

Get the last key-value pair

Computes in O(1) time.

Trait Implementations§

Source§

impl Clone for Params

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Params

Source§

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

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

impl Default for Params

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Params

Source§

type Target = IndexMap<String, Value>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'de> Deserialize<'de> for Params

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Params

Source§

impl<'a> IntoIterator for &'a Params

Source§

type Item = (&'a String, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Params

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Params

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> Ungil for T
where T: Send,