2021-10-15 15:52:08 +08:00
|
|
|
use crate::impl_def_and_def_mut;
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, ProtoBuf_Enum, Clone)]
|
|
|
|
pub enum TrashType {
|
|
|
|
Unknown = 0,
|
|
|
|
View = 1,
|
|
|
|
}
|
|
|
|
|
2021-10-15 17:09:50 +08:00
|
|
|
impl std::convert::TryFrom<i32> for TrashType {
|
|
|
|
type Error = String;
|
|
|
|
|
|
|
|
fn try_from(value: i32) -> Result<Self, Self::Error> {
|
|
|
|
match value {
|
|
|
|
0 => Ok(TrashType::Unknown),
|
|
|
|
1 => Ok(TrashType::View),
|
|
|
|
_ => Err(format!("Invalid trash type: {}", value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-15 15:52:08 +08:00
|
|
|
impl std::default::Default for TrashType {
|
|
|
|
fn default() -> Self { TrashType::Unknown }
|
|
|
|
}
|
2021-10-12 22:31:38 +08:00
|
|
|
|
|
|
|
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
2021-10-17 22:44:51 +08:00
|
|
|
pub struct TrashIdentifiers {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<TrashIdentifier>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<Vec<TrashIdentifier>> for TrashIdentifiers {
|
|
|
|
fn from(items: Vec<TrashIdentifier>) -> Self { TrashIdentifiers { items } }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<Vec<Trash>> for TrashIdentifiers {
|
|
|
|
fn from(trash: Vec<Trash>) -> Self {
|
|
|
|
let items = trash
|
|
|
|
.into_iter()
|
|
|
|
.map(|t| TrashIdentifier { id: t.id, ty: t.ty })
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
TrashIdentifiers { items }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
|
|
|
pub struct TrashIdentifier {
|
2021-10-12 22:31:38 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2021-10-15 15:52:08 +08:00
|
|
|
pub ty: TrashType,
|
2021-10-12 22:31:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, ProtoBuf, Default, Debug, Clone)]
|
|
|
|
pub struct Trash {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub modified_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub create_time: i64,
|
2021-10-15 15:52:08 +08:00
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub ty: TrashType,
|
2021-10-12 22:31:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct RepeatedTrash {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<Trash>,
|
|
|
|
}
|
2021-10-13 23:11:45 +08:00
|
|
|
|
|
|
|
impl_def_and_def_mut!(RepeatedTrash, Trash);
|