Trait bound error after upgrading to 0.17.0

1
closed
blueowlgreenfish
blueowlgreenfish
Posted 1 month ago

Trait bound error after upgrading to 0.17.0 #209

My web application works with version 0.16.2, but after upgrading to 0.17.0, set_same_site function gives error. I create a cookie like the following.

use cookie::SameSite;
use time::{Duration, OffsetDateTime};
use tower_cookies::Cookie;

pub fn create_cookie(name: &str, value: &str) -> Cookie<'static> {
    let mut c = Cookie::new(name.to_string(), value.to_string());
    let mut now = OffsetDateTime::now_utc();
    now += Duration::days(365);
    c.set_expires(now);
    c.set_same_site(SameSite::Lax);
    c.set_secure(true);
    c.set_http_only(true);
    c.set_path("/");
    c
}

Diagnostics says:

the trait bound std::option::Option<cookie::draft::SameSite>: std::convert::From<cookie::SameSite> is not satisfied the following other types implement trait std::convert::From<T>: <std::option::Option<&'a T> as std::convert::From<&'a std::option::Option>> <std::option::Option<&'a mut T> as std::convert::From<&'a mut std::option::Option>> <std::option::Option<&'a tracing_core::span::Id> as std::convert::From<&'a tracing::span::EnteredSpan>> <std::option::Option<&'a tracing_core::span::Id> as std::convert::From<&'a tracing::span::Span>> <std::option::Option<&'a tracing_core::span::Id> as std::convert::From<&'a tracing_core::span::Current>> <std::option::Option<&'static tracing_core::metadata::Metadata<'static>> as std::convert::From<&'a tracing_core::span::Current>> <std::option::Option as std::convert::From> <std::option::Option as std::convert::From<subtle::CtOption>> and 7 others required for cookie::SameSite to implement std::convert::Into<std::option::Option<cookie::draft::SameSite>>

Could anyone tell me how to fix this?

SergioBenitez
SergioBenitez
Created 1 month ago

You're almost certainly trying to use two versions of cookie at the same time. tower_cookies::Cookie is probably not the same version as cookie::Cookie, and thus not the same types.