Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntoActiveValue is not implemented for Vec<String> #1994

Open
AdamJSoftware opened this issue Dec 3, 2023 · 1 comment
Open

IntoActiveValue is not implemented for Vec<String> #1994

AdamJSoftware opened this issue Dec 3, 2023 · 1 comment

Comments

@AdamJSoftware
Copy link

Description

I am trying to implement DeriveIntoActiveModel for the following struct


#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema, DeriveIntoActiveModel)]
pub struct BusinessCreate {
    pub location: Option<String>,
    pub how_we_sell_products: Option<String>,
    ...
    pub tags: Vec<String>,
}

I have a field called tags that just contains a field of strings. When using the macro, I get the following error:

the trait `IntoActiveValue<_>` is not implemented for `std::vec::Vec<std::string::String>`

Is there a way around this?

@avtrujillo
Copy link

avtrujillo commented Dec 6, 2023

Looks like implementations are defined starting here for the following:

  • Option<V>> where V: IntoActiveValue<V> + Into<Value> + Nullable,
  • Option<Option<V>> where V: IntoActiveValue<V> + Into<Value> + Nullable,
  • bool
  • i8
  • i16
  • i32
  • i64
  • u8
  • u16
  • u32
  • u64
  • f32
  • f64
  • &'static str
  • String
  • Vec<u8>

The first two are implemented manually, with the rest being implemented using the impl_into_active_value macro. The explanation for the implementation being only for Vec<u8> and not other Vec types is presumably that ActiveValue::Set(V) has the trait bound V: Into, and Into is implemented for Vec<u8> because Vec<u8> is converted into Value::Bytes. It's also implemented here for Vec<V>, but inside a module that requires the "postgres-array" feature to be enabled. Any fix for this would therefore need to be gated behind the "postgres-array" feature in order to work properly.

Edit: I tried doing this

#[cfg(feature = "postgres-array")]
impl IntoActiveValue<Vec> for Vec
where
V: IntoActiveValue + Into + Nullable + sea_query::ValueType + sea_query::with_array::NotU8

but got an error helpfully informing me that

upstream crates may add a new impl of trait sea_query::with_array::NotU8 for type u8 in future versions

Removing the sea_query::with_array::NotU8 bound produces conflicting implementations. Removing the NotU8 bound and deleting impl_into_active_value!(Vec<u8>) just gives me an error informing me that

the trait bound V: NotU8 is not satisfied
required for sea_query::Value to implement From<Vec<V>>
required for Vec<V> to implement `Into<sea_query::Value>

So it looks like we might be blocked on the stabilization of negative trait bounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants