oscartbeaumont / tauri-specta

Completely typesafe Tauri commands
MIT License
289 stars 26 forks source link

error[E0053]: method `inline` has an incompatible type for trait #65

Closed codad5 closed 6 months ago

codad5 commented 6 months ago

Hello , using v2.0.0-rc.5 i am getting this error

  Compiling specta v2.0.0-rc.5
error[E0053]: method `inline` has an incompatible type for trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\impls.rs:169:10
    |
169 | #[derive(Type)]
    |          ^^^^
    |          |
    |          expected `datatype::DefOpts<'_>`, found `&mut BTreeMap<SpectaID, ...>`
    |          help: change the parameter type to match the trait: `datatype::DefOpts<'_>`
    |
note: type in trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\mod.rs:22:21
    |
22  |     fn inline(opts: DefOpts, generics: &[DataType]) -> DataType;
    |                     ^^^^^^^
    = note: expected signature `fn(datatype::DefOpts<'_>, &[datatype::DataType]) -> datatype::DataType`
               found signature `fn(&mut std::collections::BTreeMap<specta_id::SpectaID, Option<named::NamedDataType>>, &[datatype::DataType]) -> datatype::DataType`
    = note: this error originates in the derive macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0053]: method `definition` has an incompatible type for trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\impls.rs:169:10
    |
169 | #[derive(Type)]
    |          ^^^^
    |          |
    |          expected `datatype::DefOpts<'_>`, found `&mut BTreeMap<SpectaID, ...>`
    |          help: change the parameter type to match the trait: `datatype::DefOpts<'_>`
    |
note: type in trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\mod.rs:37:25
    |
37  |     fn definition(opts: DefOpts) -> DataType {
    |                         ^^^^^^^
    = note: expected signature `fn(datatype::DefOpts<'_>) -> datatype::DataType`
               found signature `fn(&mut std::collections::BTreeMap<specta_id::SpectaID, Option<named::NamedDataType>>) -> datatype::DataType`
    = note: this error originates in the derive macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0053]: method `reference` has an incompatible type for trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\impls.rs:169:10
    |
169 | #[derive(Type)]
    |          ^^^^
    |          |
    |          expected `datatype::DefOpts<'_>`, found `&mut BTreeMap<SpectaID, ...>`
    |          help: change the parameter type to match the trait: `datatype::DefOpts<'_>`
    |
note: type in trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\mod.rs:51:24
    |
51  |     fn reference(opts: DefOpts, generics: &[DataType]) -> Reference {
    |                        ^^^^^^^
    = note: expected signature `fn(datatype::DefOpts<'_>, &[datatype::DataType]) -> Reference`
               found signature `fn(&mut std::collections::BTreeMap<specta_id::SpectaID, Option<named::NamedDataType>>, &[datatype::DataType]) -> Reference`
    = note: this error originates in the derive macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0053]: method `named_data_type` has an incompatible type for trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\impls.rs:169:10
    |
169 | #[derive(Type)]
    |          ^^^^
    |          |
    |          expected `datatype::DefOpts<'_>`, found `&mut BTreeMap<SpectaID, ...>`
    |          help: change the parameter type to match the trait: `datatype::DefOpts<'_>`
    |
note: type in trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\mod.rs:63:30
    |
63  |     fn named_data_type(opts: DefOpts, generics: &[DataType]) -> NamedDataType;
    |                              ^^^^^^^
    = note: expected signature `fn(datatype::DefOpts<'_>, &[datatype::DataType]) -> named::NamedDataType`
               found signature `fn(&mut std::collections::BTreeMap<specta_id::SpectaID, Option<named::NamedDataType>>, &[datatype::DataType]) -> named::NamedDataType`
    = note: this error originates in the derive macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0053]: method `definition_named_data_type` has an incompatible type for trait
   --> C:\Users\User\.cargo\registry\src\index.crates.io-6f17d22bba15001f\specta-2.0.0-rc.5\src\type\impls.rs:169:10
    |
169 | #[derive(Type)]
    |          ^^^^
    |          |
    |          expected `datatype::DefOpts<'_>`, found `&mut BTreeMap<SpectaID, ...>`
    |          help: change the parameter type to match the trait: `datatype::DefOpts<'_>`
    |
note: type in trait

Here are my code cargo.toml

specta = "=2.0.0-rc.5"
tauri-specta = { version = "=2.0.0-rc.2", features = ["javascript", "typescript"] }

response.rs

use specta::Type;
use serde::{Deserialize, Serialize};
use super::auth::AccessToken;
// save token response 
#[derive(Serialize, Type)]
pub struct SaveTokenResponse {
    pub message: String,
    pub token: String,
    pub success: bool,
}

#[derive(Serialize, Type)]
pub struct SaveAccessTokenResponse {
    pub message: String,
    pub success: bool,
    pub token: AccessToken,
}

#[derive(Serialize, Type)]
pub struct GreetResponse {
    pub message: String,
}

argument.rs

use specta::Type;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Type)]
pub struct MyCustomArgumentType {
    pub foo: String,
    pub bar: i32,
}

tauri_command.rs

use std::env;

use tauri;

// super mod imports;
use super::auth::{AccessToken, Auth};
use super::filehelper::{ENV_FILE, ACCESS_TOKEN_FILE};

#[tauri::command]
#[specta::specta]
pub fn test_command() -> String {
    println!("access token path: {}", &*ACCESS_TOKEN_FILE);
    println!("ENV_FILE: {}", ENV_FILE);
    return env::var("DB_PASSWORD").unwrap();
}

#[tauri::command]
#[specta::specta]
pub fn greet(name: String) -> GreetResponse {
    GreetResponse {
        message: format!("Hello, {}! You've been greeted from Rust!", name),
    };
}

// remember to call `.manage(MyState::default())`
#[tauri::command]
#[specta::specta]
pub fn save_access_token(token: String) -> SaveAccessTokenResponse {
    dotenv::from_filename(ENV_FILE).ok();
    return Auth::save_access_token(token);
}

// a command to load the access token from the file
#[tauri::command]
#[specta::specta]
pub fn load_access_token() -> AccessToken {
    dotenv::from_filename(ENV_FILE).ok();
    return Auth::load_access_token();
}

#[tauri::command]
#[specta::specta]
pub fn save_code(code: String) -> SaveTokenResponse {
    dotenv::from_filename(ENV_FILE).ok();
    return Auth::save_auth_code(code);
}

#[tauri::command]
#[specta::specta]
pub fn load_code() -> String {
    dotenv::from_filename(ENV_FILE).ok();
    return Auth::load_auth_code();
}

main.rs

// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

mod libs;

use tauri_plugin_log::{LogTarget};
use specta::collect_types;
use tauri_specta::{ts, js};

use libs::tauri_actions::{save_access_token,load_access_token, greet, test_command, save_code, load_code};
use libs::filehelper::{ENV_FILE, initialize_user_files};

fn specta_builder() {
    let specta_builder = tauri_specta::ts::builder()
        .commands(tauri_specta::collect_commands![
            save_access_token,
            load_access_token,
            greet,
            test_command,
            save_code,
            load_code,
        ]);

    #[cfg(debug_assertions)] // <- Only export on non-release builds
    let specta_builder = specta_builder.path("../src/helpers/commands.ts");

    specta_builder.into_plugin()
}

fn main() {
    dotenv::from_filename(ENV_FILE).ok();
    initialize_user_files();

    let specta_builder = specta_builder();

    tauri::Builder::default()
    .plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
        println!("{}, {argv:?}, {cwd}", app.package_info().name);
        // app.emit_all("single-instance", Payload { args: argv, cwd }).unwrap();
    }))
        .plugin(specta_builder)
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
oscartbeaumont commented 6 months ago

Both Tauri Specta version 2.0.0-rc.2 and 2.0.0-rc.1 had issues in them which were missed before release (if you check docs.rs they failed to build docs).

Please try upgrading to Tauri Specta 2.0.0-rc.4 & Specta 2.0.0-rc.7. I can't provide support for older versions.

codad5 commented 6 months ago

Both Tauri Specta version 2.0.0-rc.2 and 2.0.0-rc.1 had issues in them which were missed before release (if you check docs.rs they failed to build docs).

Please try upgrading to Tauri Specta 2.0.0-rc.4 & Specta 2.0.0-rc.7. I can't provide support for older versions.

Thanks al🤗t , then I guess there need to be some changes in the docs(README.md) , cause it would be misleading to others

oscartbeaumont commented 6 months ago

Thanks @tbrockman for updating the docs, I completely missed that they were outdated!