pub struct Intent {
pub action: String,
pub params: BTreeMap<String, String>,
}Expand description
A human-readable action with named, canonically-ordered parameters.
Parameters are sorted by key before hashing, so two Intent values
with identical fields but different insertion order produce the same hash.
This makes intent construction order-independent and audit logs readable.
§Examples
use a1::Intent;
let intent = Intent::new("trade.equity").unwrap()
.param("symbol", "AAPL")
.param("side", "buy")
.param("limit_usd", "182.50")
.param("qty", "100");
let h = intent.hash();
assert_ne!(h, [0u8; 32]);Fields§
§action: StringAction identifier (e.g. "trade.equity", "query.portfolio").
params: BTreeMap<String, String>Named parameters, sorted by key for canonical serialization.
Implementations§
Source§impl Intent
impl Intent
Sourcepub fn new(action: impl Into<String>) -> Result<Self, A1Error>
pub fn new(action: impl Into<String>) -> Result<Self, A1Error>
Create a new intent. Returns A1Error::WireFormatError if the action string
is empty or exceeds MAX_ACTION_LEN.
§Examples
use a1::Intent;
let intent = Intent::new("trade.equity").unwrap()
.param("symbol", "AAPL")
.param("side", "buy");
assert!(Intent::new("").is_err());Sourcepub fn try_new(action: impl Into<String>) -> Result<Self, A1Error>
pub fn try_new(action: impl Into<String>) -> Result<Self, A1Error>
Alias for new. Prefer new in new code; retained for API symmetry with try_param.
Sourcepub fn param(self, key: impl Into<String>, value: impl Into<String>) -> Self
pub fn param(self, key: impl Into<String>, value: impl Into<String>) -> Self
Attach a named parameter. Replaces any existing value for the same key.
Panics on debug if limits are exceeded.
Use try_param for validation-critical paths.
Sourcepub fn try_param(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Result<Self, A1Error>
pub fn try_param( self, key: impl Into<String>, value: impl Into<String>, ) -> Result<Self, A1Error>
Attach a named parameter. Replaces any existing value for the same key.
Returns A1Error::WireFormatError if limits are exceeded.
Keys and values are normalized to lowercase and trimmed to ensure deterministic hashing regardless of how the caller constructs them.
Sourcepub fn hash(&self) -> IntentHash
pub fn hash(&self) -> IntentHash
Compute the domain-separated hash of this intent.
Uses a prefix-free canonical encoding: each field is length-prefixed before its content, preventing length-extension and collision attacks.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Intent
impl<'de> Deserialize<'de> for Intent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Intent
impl StructuralPartialEq for Intent
Auto Trait Implementations§
impl Freeze for Intent
impl RefUnwindSafe for Intent
impl Send for Intent
impl Sync for Intent
impl Unpin for Intent
impl UnsafeUnpin for Intent
impl UnwindSafe for Intent
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.