#[derive(Insertable)]没有为`std :: string :: String`

时间:2018-05-14 04:25:38

标签: rust rust-diesel

我收到此错误:

#[derive(Insertable, Queryable, Identifiable, Debug, PartialEq)]
         ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `std::string::String`

当我尝试编译此struct时:

#[derive(Insertable, Queryable, Identifiable, Debug, PartialEq)]
#[table_name = "example_table"]
pub struct SigninLog {
    pub id: i32,
    pub user_group: UserRoleEnum,
    pub created_at: Option<SystemTime>,
    pub optional_data: Option<String>
}

是因为它包含自定义enum还是Option<String>?如果这是问题,我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

一般情况下,为了#[derive(X)] structX所有成员都必须实施Insertable。这可能不是String的情况,因为它不是标准特征,但您可能想要验证这一点;在您的情况下,optional_data未在Option<T>内为Option实施;它是针对Insertable实施的,因此封闭它的diesel不是问题。

您可能希望手动实施Math.Round(88.5, MidpointRounding.AwayFromZero) // The result is 89 Math.Round(88.5, MidpointRounding.ToEven) // The result is 88 ;我没有使用过public class SelectSurveyPageTest extends TestBase { SelectSurveyPage sp; LoginPage lp; WeightOfPatientQue weightOfPatient ; public SelectSurveyPageTest() throws InvocationTargetException { super(); } @Test(priority=1) public void loginValid() throws InterruptedException { String str2=sp.loginValidation(); System.out.println(str2); } @Test(priority=2) public void surveySelection() throws InterruptedException { //String str2=sp.loginValidation(); weightOfPatient=sp.surveySelection(); } @BeforeMethod public void surverySetUp() throws Exception { initialization(); lp=new LoginPage(); sp=lp.loginPageTest1(); } @AfterMethod public void surveyTearDown() { driver.quit(); } } - 可能有一种更简单的方法可以做到这一点。