From: Simon Tatham Date: Sat, 23 Dec 2023 11:15:28 +0000 (+0000) Subject: Move the types out into a separate module. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=9fde14114b3e4b677de497b95d47a85b312c42c7;p=mastodonochrome.git Move the types out into a separate module. --- diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..cd40856 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod types; diff --git a/src/main.rs b/src/main.rs index df089dd..9804632 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,121 +1,4 @@ -use chrono::{DateTime,Utc}; -use serde::{Deserialize, Serialize}; -use serde_json::Result; -use std::boxed::Box; -use std::option::Option; - -#[derive(Serialize, Deserialize, Debug)] -struct AccountField { - name: String, - value: String, - verified_at: Option>, -} - -#[derive(Serialize, Deserialize, Debug)] -struct Account { - id: String, - username: String, - acct: String, - url: String, - display_name: String, - note: String, - avatar: String, - avatar_static: String, - header: String, - header_static: String, - locked: bool, - fields: Vec, - // emojis: Vec, - bot: bool, - group: bool, - discoverable: Option, - noindex: Option, - moved: Option>, - suspended: Option, - limited: Option, - created_at: DateTime, - last_status_at: Option, // this lacks a timezone, so serde - // can't deserialize it in the obvious way - statuses_count: u64, - followers_count: u64, - following_count: u64, -} - -#[derive(Serialize, Deserialize, Debug)] -struct Application { - name: String, - website: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -enum Visibility { - #[serde(rename = "public")] Public, - #[serde(rename = "unlisted")] Unlisted, - #[serde(rename = "private")] Private, - #[serde(rename = "direct")] Direct, -} - -#[derive(Serialize, Deserialize, Debug)] -enum MediaType { - #[serde(rename = "unknown")] Unknown, - #[serde(rename = "image")] Image, - #[serde(rename = "gifv")] GifV, - #[serde(rename = "video")] Video, - #[serde(rename = "audio")] Audio, -} - -#[derive(Serialize, Deserialize, Debug)] -struct MediaAttachment { - id: String, - #[serde(rename="type")] mediatype: MediaType, - url: String, - preview_url: String, - remote_url: Option, - description: Option, -} - -#[derive(Serialize, Deserialize, Debug)] -struct StatusMention { - id: String, - username: String, - url: String, - acct: String, -} - -#[derive(Serialize, Deserialize, Debug)] -struct Status { - id: String, - uri: String, - created_at: DateTime, - account: Account, - content: String, - visibility: Visibility, - sensitive: bool, - spoiler_text: String, - media_attachments: Vec, - application: Option, - mentions: Vec, - // tags: Vec, - // emojis: Vec, - reblogs_count: u64, - favourites_count: u64, - replies_count: u64, - url: String, - in_reply_to_id: Option, - in_reply_to_account_id: Option, - reblog: Option>, - // poll: Option, - // card: Option, - language: Option, - text: Option, - edited_at: Option>, - favourited: Option, - reblogged: Option, - muted: Option, - bookmarked: Option, - pinned: Option, - filtered: Option, -} +use mastodonochrome::types::*; fn main() { let client = reqwest::blocking::Client::new(); diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..4da4ea1 --- /dev/null +++ b/src/types.rs @@ -0,0 +1,117 @@ +use chrono::{DateTime,Utc}; +use serde::{Deserialize, Serialize}; +use std::boxed::Box; +use std::option::Option; + +#[derive(Serialize, Deserialize, Debug)] +pub struct AccountField { + name: String, + value: String, + verified_at: Option>, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Account { + id: String, + username: String, + acct: String, + url: String, + display_name: String, + note: String, + avatar: String, + avatar_static: String, + header: String, + header_static: String, + locked: bool, + fields: Vec, + // emojis: Vec, + bot: bool, + group: bool, + discoverable: Option, + noindex: Option, + moved: Option>, + suspended: Option, + limited: Option, + created_at: DateTime, + last_status_at: Option, // this lacks a timezone, so serde + // can't deserialize it in the obvious way + statuses_count: u64, + followers_count: u64, + following_count: u64, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Application { + name: String, + website: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub enum Visibility { + #[serde(rename = "public")] Public, + #[serde(rename = "unlisted")] Unlisted, + #[serde(rename = "private")] Private, + #[serde(rename = "direct")] Direct, +} + +#[derive(Serialize, Deserialize, Debug)] +pub enum MediaType { + #[serde(rename = "unknown")] Unknown, + #[serde(rename = "image")] Image, + #[serde(rename = "gifv")] GifV, + #[serde(rename = "video")] Video, + #[serde(rename = "audio")] Audio, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct MediaAttachment { + id: String, + #[serde(rename="type")] mediatype: MediaType, + url: String, + preview_url: String, + remote_url: Option, + description: Option, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct StatusMention { + id: String, + username: String, + url: String, + acct: String, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Status { + id: String, + uri: String, + created_at: DateTime, + account: Account, + content: String, + visibility: Visibility, + sensitive: bool, + spoiler_text: String, + media_attachments: Vec, + application: Option, + mentions: Vec, + // tags: Vec, + // emojis: Vec, + reblogs_count: u64, + favourites_count: u64, + replies_count: u64, + url: String, + in_reply_to_id: Option, + in_reply_to_account_id: Option, + reblog: Option>, + // poll: Option, + // card: Option, + language: Option, + text: Option, + edited_at: Option>, + favourited: Option, + reblogged: Option, + muted: Option, + bookmarked: Option, + pinned: Option, + filtered: Option, +}