Skip to content

How to Specify Enum Literals? #76

@wbrickner

Description

@wbrickner

Hello 👋🏻

I am trying to update a document.

I need to set the field standing, of type UserStanding:

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum UserStanding {
  /// the request is received, pending approval
  Pending,

  /// user account approved, active, fully enabled, etc.
  Active
}

#[derive(Model, Serialize, Deserialize, Clone, Debug)]
pub struct User {
  /// User standing (for customer signup requests)
  pub standing: UserStanding
}

When I try to do this:

let update = {
    doc! {
      "$set": doc! {
        "location": &form.location,
        "standing": UserStanding::Active
      }
    }
  };

let result = User::find_one_and_update(
    &db, 
    doc! { "id": &path.user_id }, 
    update, None
  ).await;

I get the error

error[E0277]: the trait bound `Bson: From<UserStanding>` is not satisfied
  --> src/services/dashboard/users/review.rs:24:15
   |
24 |         "$set": doc! {
   |  _______________^
25 | |         "location": &form.location,
26 | |         "standing": UserStanding::Active
27 | |       }
   | |_______^ the trait `From<UserStanding>` is not implemented for `Bson`
   |
   = help: the following implementations were found:
             <Bson as From<&T>>
             <Bson as From<&[T]>>
             <Bson as From<&str>>
             <Bson as From<Vec<T>>>
           and 19 others
   = note: required by `std::convert::From::from`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions