Today when I am build the rust project, tell me this error:
--> src/biz/music/playlist.rs:22:5
|
22 | use std::io;
| ^^^^^^^
error[E0308]: mismatched types
--> src/biz/music/playlist.rs:38:20
|
38 | creator: user,
| ^^^^ expected struct `playlist_response::user_response::UserResponse`, found struct `playlist::user_response::UserResponse`
error: aborting due to previous error; 5 warnings emitted
I only define one UserResponse
struct, why still conflict? what should I do to avoid this problem? this is the code I am using now:
#[path = "../../config/db/config.rs"]
mod config;
#[path = "../../schema.rs"]
mod schema;
#[path = "../../models.rs"]
mod models;
#[path = "../../model/request/music/play_record_request.rs"]
mod play_record_request;
#[path = "../../model/response/api_response.rs"]
mod api_response;
#[path = "../../model/response/playlist_response.rs"]
mod playlist_response;
#[path = "../../model/response/user/user_response.rs"]
mod user_response;
use crate::diesel::prelude::*;
use models::{ QueryPlaylist };
use api_response::ApiResponse;
use playlist_response::PlaylistResponse;
use rocket::response::content;
use std::io;
use user_response::UserResponse;
#[get("/v1/playlist")]
pub fn user_playlist() -> content::Json<String> {
use schema::playlist::dsl::*;
let connection = config::establish_connection();
let results = playlist.filter(creator.eq(1))
.limit(1)
.load::<QueryPlaylist>(&connection)
.expect("Error loading posts");
let mut reslist = Vec::new();
let user = UserResponse{ id: 0, name: "test".to_string() };
for re in &results {
let playlist_dto = PlaylistResponse{
id: re.id,
creator: user,
name: "test".to_string(),
coverUrl: re.cover_url,
description: re.description,
subscribed: re.subscribed,
subscribedCount: re.subscribed_count,
commentCount: re.comment_count,
shareCount: re.share_count,
playCount: re.play_count
};
reslist.push(playlist_dto);
}
let res = ApiResponse {
result: reslist,
..Default::default()
};
let response_json = serde_json::to_string(&res).unwrap();
return content::Json(response_json);
}