Why did package build fail but test succeed

use crate::template::TEMPLATE;
use mybatis_core::db::DriverType;

pub trait SqlRule {
    fn make_where(&self, where_sql: &str) -> String {

        let sql = where_sql.trim_start();
        if sql.is_empty() {
            return String::new();
        }
        if sql.starts_with(TEMPLATE.order_by.right_space)
            || sql.starts_with(TEMPLATE.group_by.right_space)
            || sql.starts_with(TEMPLATE.limit.right_space)
        {
            sql.to_string()
        } else {
            format!(
                " {} {} ",
                TEMPLATE.r#where.value,
                sql.trim_start_matches(TEMPLATE.r#where.right_space)
                    .trim_start_matches(TEMPLATE.and.right_space)
                    .trim_start_matches(TEMPLATE.or.right_space)
            )
        }
    }

    fn make_left_insert_where(&self, insert_sql: &str, where_sql: &str) -> String {
        let sql = where_sql
            .trim()
            .trim_start_matches(TEMPLATE.r#where.right_space)
            .trim_start_matches(TEMPLATE.and.right_space);
        if sql.is_empty() {
            return insert_sql.to_string();
        }
        if sql.starts_with(TEMPLATE.order_by.right_space)
            || sql.starts_with(TEMPLATE.group_by.right_space)
            || sql.starts_with(TEMPLATE.limit.right_space)
        {
            format!(
                " {} {} {}",
                TEMPLATE.r#where.value,
                insert_sql
                    .trim()
                    .trim_end_matches(TEMPLATE.and.left_space),
                sql
            )
        } else {
            format!(
                " {} {} {} {}",
                TEMPLATE.r#where.value,
                insert_sql
                    .trim()
                    .trim_end_matches(TEMPLATE.and.left_space),
                TEMPLATE.and.value,
                sql
            )
        }
    }
}

impl SqlRule for DriverType {}
fn make_select_sql<T>(rb: &Mybatis, column: &str, w: &Wrapper) -> Result<String>
    where
        T: CRUDTable,
{
    let driver_type = rb.driver_type().unwrap();

    let where_sql = driver_type.make_where(&w.sql);
    let table_name = choose_dyn_table_name::<T>(w);
    Ok(format!(
        "{} {} {} {} {}",
        TEMPLATE.select.value,
        column,
        TEMPLATE.from.value,
        table_name,
        where_sql,
    ))
}

package error:

error[E0599]: no method named `make_where` found for enum `DriverType` in the current scope
   --> src/crud.rs:908:33
    |
908 |     let where_sql = driver_type.make_where(&w.sql);
    |                                 ^^^^^^^^^^ method not found in `DriverType`

My two codes come from different crates

#[cfg(feature = "postgres")]
pub mod bind_pg;
#[cfg(feature = "mysql")]
pub mod bind_mysql;
#[cfg(feature = "sqlite")]
pub mod bind_sqlite;
#[cfg(feature = "mssql")]
pub mod bind_mssql;


use std::time::Duration;
use rbson::Bson;

use chrono::NaiveDateTime;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};

pub use db_adapter::{
    DBConnectOption, DBExecResult, DBPool, DBPoolConn, DBQuery, DBTx,
};
use crate::convert::StmtConvert;
use crate::db::db_adapter::DataDecoder;

pub mod db_adapter;


#[derive(Debug)]
pub struct DBPoolOptions {
    pub max_connections: u32,
    pub min_connections: u32,
    pub connect_timeout: Duration,
    pub max_lifetime: Option<Duration>,
    pub idle_timeout: Option<Duration>,
    pub test_before_acquire: bool,
    pub decoder: Box<dyn DataDecoder>,
}

impl Default for DBPoolOptions {
    fn default() -> Self {
        Self {
            // pool a maximum of 10 connections to the same database
            max_connections: 10,
            // don't open connections until necessary
            min_connections: 0,
            // try to connect for 10 seconds before erroring
            connect_timeout: Duration::from_secs(60),
            // reap connections that have been alive > 30 minutes
            // prevents unbounded live-leaking of memory due to naive prepared statement caching
            // see src/cache.rs for context
            max_lifetime: Some(Duration::from_secs(1800)),
            // don't reap connections based on idle time
            idle_timeout: None,
            // If true, test the health of a connection on acquire
            test_before_acquire: true,
            decoder: Box::new(DefaultDecoder {}),
        }
    }
}

impl DBPoolOptions {
    pub fn new() -> Self {
        DBPoolOptions::default()
    }
}

#[derive(Clone, Debug)]
pub struct DefaultDecoder {}

impl DataDecoder for DefaultDecoder {
    fn decode(&self, _key: &str, _data: &mut Bson) -> crate::Result<()> {
        return Ok(());
    }
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy, Eq, PartialEq)]
pub enum DriverType {
    None = 0,
    Mysql = 1,
    Postgres = 2,
    Sqlite = 3,
    Mssql = 4,
}

impl DriverType {
    pub fn is_number_type(&self) -> bool {
        match self {
            DriverType::Postgres|DriverType::Mssql => {
                return true;
            }
            _ => {
                return false;
            }
        }
    }
}


Have you imported the SqlRule trait with a use declaration?

I'm pretty sure I imported it

use mybatis_sql::rule::SqlRule;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.