Skip to main content

yush_core/
lib.rs

1//! Provides the core types and impls for `yush`.
2
3use serde::{Deserialize, Serialize};
4
5/// This is to allow a [`Blob`] to distinguish between different kinds
6/// of media
7#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
8pub enum Kind {
9    Video(Video),
10}
11
12/// A video
13#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
14pub struct Video {
15    /// The length of the video in seconds.
16    pub len: f64,
17}
18
19/// An entry of metadata to some binary object.
20#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
21pub struct Blob {
22    /// The underlying target.
23    pub filename: String,
24    /// The path to the preview of the filename
25    pub preview: String,
26    /// The title of this work.
27    pub title: String,
28    /// The date of this work.
29    // TODO use a timestamp, this is fine for a prototype.
30    pub date: Option<String>,
31    /// The size in bytes
32    pub size: usize,
33    /// The kind of this blob
34    pub kind: Kind,
35}
36
37/// A newtype for a vector of blobs
38#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
39pub struct Blobs {
40    pub blobs: Vec<Blob>,
41}
42
43impl Kind {
44    /// Convert this kind into a [`Video`]
45    pub fn as_video(&self) -> Option<&Video> {
46        match self {
47            Self::Video(v) => Some(v),
48        }
49    }
50}