#[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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for State
impl<'de> Deserialize<'de> for State
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 State
Source§impl Ord for State
impl Ord for State
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for State
impl PartialOrd for State
impl StructuralPartialEq for State
Auto Trait Implementations§
impl Forget for State
impl Freeze for State
impl Move for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
impl UnwindSafe for State
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.