trash_rev.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use crate::entities::trash::{Trash, TrashType};
  2. use crate::entities::{RepeatedTrash, TrashId};
  3. use serde::{Deserialize, Serialize};
  4. #[derive(Default, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
  5. pub struct TrashRevision {
  6. pub id: String,
  7. pub name: String,
  8. pub modified_time: i64,
  9. pub create_time: i64,
  10. pub ty: TrashType,
  11. }
  12. impl std::convert::From<Vec<TrashRevision>> for RepeatedTrash {
  13. fn from(trash_revs: Vec<TrashRevision>) -> Self {
  14. let items: Vec<Trash> = trash_revs.into_iter().map(|trash_rev| trash_rev.into()).collect();
  15. RepeatedTrash { items }
  16. }
  17. }
  18. impl std::convert::From<TrashRevision> for Trash {
  19. fn from(trash_rev: TrashRevision) -> Self {
  20. Trash {
  21. id: trash_rev.id,
  22. name: trash_rev.name,
  23. modified_time: trash_rev.modified_time,
  24. create_time: trash_rev.create_time,
  25. ty: trash_rev.ty,
  26. }
  27. }
  28. }
  29. impl std::convert::From<Trash> for TrashRevision {
  30. fn from(trash: Trash) -> Self {
  31. TrashRevision {
  32. id: trash.id,
  33. name: trash.name,
  34. modified_time: trash.modified_time,
  35. create_time: trash.create_time,
  36. ty: trash.ty,
  37. }
  38. }
  39. }
  40. impl std::convert::From<&TrashRevision> for TrashId {
  41. fn from(trash: &TrashRevision) -> Self {
  42. TrashId {
  43. id: trash.id.clone(),
  44. ty: trash.ty.clone(),
  45. }
  46. }
  47. }