1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 10:27:42 +02:00

fmt with new width

This commit is contained in:
Rob Ede
2021-08-30 23:27:44 +01:00
parent c6f579790f
commit e10937103e
18 changed files with 54 additions and 144 deletions

View File

@ -77,8 +77,7 @@ impl CookieSessionInner {
return Ok(());
}
let value =
serde_json::to_string(&state).map_err(CookieSessionError::Serialize)?;
let value = serde_json::to_string(&state).map_err(CookieSessionError::Serialize)?;
if value.len() > 4064 {
return Err(CookieSessionError::Overflow.into());
@ -143,9 +142,7 @@ impl CookieSessionInner {
let cookie_opt = match self.security {
CookieSecurity::Signed => jar.signed(&self.key).get(&self.name),
CookieSecurity::Private => {
jar.private(&self.key).get(&self.name)
}
CookieSecurity::Private => jar.private(&self.key).get(&self.name),
};
if let Some(cookie) = cookie_opt {
@ -528,10 +525,7 @@ mod tests {
let _ = ses.insert("counter", 100);
"test"
}))
.service(
web::resource("/test/")
.to(|| async move { "no-changes-in-session" }),
),
.service(web::resource("/test/").to(|| async move { "no-changes-in-session" })),
)
.await;

View File

@ -165,11 +165,7 @@ impl Session {
///
/// Any serializable value can be used and will be encoded as JSON in session data, hence why
/// only a reference to the value is taken.
pub fn insert(
&self,
key: impl Into<String>,
value: impl Serialize,
) -> Result<(), Error> {
pub fn insert(&self, key: impl Into<String>, value: impl Serialize) -> Result<(), Error> {
let mut inner = self.0.borrow_mut();
if inner.status != SessionStatus::Purged {
@ -199,10 +195,7 @@ impl Session {
///
/// Returns None if key was not present in session. Returns T if deserialization succeeds,
/// otherwise returns un-deserialized JSON string.
pub fn remove_as<T: DeserializeOwned>(
&self,
key: &str,
) -> Option<Result<T, String>> {
pub fn remove_as<T: DeserializeOwned>(&self, key: &str) -> Option<Result<T, String>> {
self.remove(key)
.map(|val_str| match serde_json::from_str(&val_str) {
Ok(val) => Ok(val),
@ -259,10 +252,7 @@ impl Session {
/// vec![("counter".to_string(), serde_json::to_string(&0).unwrap())],
/// );
/// ```
pub fn set_session(
req: &mut ServiceRequest,
data: impl IntoIterator<Item = (String, String)>,
) {
pub fn set_session(req: &mut ServiceRequest, data: impl IntoIterator<Item = (String, String)>) {
let session = Session::get_session(&mut *req.extensions_mut());
let mut inner = session.0.borrow_mut();
inner.state.extend(data);