#[non_exhaustive]pub struct State(/* private fields */);Expand description
Opaque server state token (RFC 8620 §1.2).
Returned by /get and /changes methods. Clients echo it back in
sinceState / ifInState parameters. Treat as opaque — no structure assumed.
§Migrating from String-typed code
Earlier revisions of this crate exposed state fields as
pub session_state: String on crate::JmapResponse and similar
shapes. The current revision uses the State newtype for type
safety. The wire format is unchanged (State is
#[serde(transparent)] over String). The Rust API conversions
available to callers migrating from String:
- Read as
&str:state.as_ref()(viaAsRef<str>) orformat!("{state}")(viaDisplay). - Compare to a literal:
state == "abc"(viaPartialEq<str>). - Move into an owned
String:state.into_inner(). - Borrow as
&String: not directly available; useas_ref()to get&strinstead. - Build from
&strorString:State::from("abc")orState::from(my_string)(viaFrom<&str>/From<String>).
Callers passing a State to a function that takes String should
either change the signature to impl AsRef<str> or call
state.into_inner() at the boundary. Callers keying a
HashMap<String, _> by state token can either rekey by
HashMap<State, _> (State implements Hash + Eq) or call
state.into_inner() at insertion / lookup time.
Implementations§
Source§impl State
impl State
Sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consumes the value and returns the inner String.
Source§impl State
impl State
Sourcepub fn new_validated(s: impl Into<String>) -> Result<Self, ValidationError>
pub fn new_validated(s: impl Into<String>) -> Result<Self, ValidationError>
Construct a State with RFC 8620 §1.2 validation.
Rejects empty strings. RFC 8620 §1.2 requires State to be non-empty; no character-set restriction is imposed.
Use State::from when the value is known to be valid.