chiark / gitweb /
Move the types out into a separate module.
authorSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 11:15:28 +0000 (11:15 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 23 Dec 2023 11:16:25 +0000 (11:16 +0000)
src/lib.rs [new file with mode: 0644]
src/main.rs
src/types.rs [new file with mode: 0644]

diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644 (file)
index 0000000..cd40856
--- /dev/null
@@ -0,0 +1 @@
+pub mod types;
index df089dd0baa08d223a9dcf5120550a763b25c7c5..9804632eba533db5a72c22bc2c1e353e8b08cf98 100644 (file)
@@ -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<DateTime<Utc>>,
-}
-
-#[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<AccountField>,
-    // emojis: Vec<Emoji>,
-    bot: bool,
-    group: bool,
-    discoverable: Option<bool>,
-    noindex: Option<bool>,
-    moved: Option<Box<Account>>,
-    suspended: Option<bool>,
-    limited: Option<bool>,
-    created_at: DateTime<Utc>,
-    last_status_at: Option<String>, // 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<String>,
-}
-
-#[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<String>,
-    description: Option<String>,
-}
-
-#[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<Utc>,
-    account: Account,
-    content: String,
-    visibility: Visibility,
-    sensitive: bool,
-    spoiler_text: String,
-    media_attachments: Vec<MediaAttachment>,
-    application: Option<Application>,
-    mentions: Vec<StatusMention>,
-    // tags: Vec<Hashtag>,
-    // emojis: Vec<Emoji>,
-    reblogs_count: u64,
-    favourites_count: u64,
-    replies_count: u64,
-    url: String,
-    in_reply_to_id: Option<String>,
-    in_reply_to_account_id: Option<String>,
-    reblog: Option<Box<Status>>,
-    // poll: Option<Poll>,
-    // card: Option<PreviewCard>,
-    language: Option<String>,
-    text: Option<String>,
-    edited_at: Option<DateTime<Utc>>,
-    favourited: Option<bool>,
-    reblogged: Option<bool>,
-    muted: Option<bool>,
-    bookmarked: Option<bool>,
-    pinned: Option<bool>,
-    filtered: Option<bool>,
-}
+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 (file)
index 0000000..4da4ea1
--- /dev/null
@@ -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<DateTime<Utc>>,
+}
+
+#[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<AccountField>,
+    // emojis: Vec<Emoji>,
+    bot: bool,
+    group: bool,
+    discoverable: Option<bool>,
+    noindex: Option<bool>,
+    moved: Option<Box<Account>>,
+    suspended: Option<bool>,
+    limited: Option<bool>,
+    created_at: DateTime<Utc>,
+    last_status_at: Option<String>, // 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<String>,
+}
+
+#[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<String>,
+    description: Option<String>,
+}
+
+#[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<Utc>,
+    account: Account,
+    content: String,
+    visibility: Visibility,
+    sensitive: bool,
+    spoiler_text: String,
+    media_attachments: Vec<MediaAttachment>,
+    application: Option<Application>,
+    mentions: Vec<StatusMention>,
+    // tags: Vec<Hashtag>,
+    // emojis: Vec<Emoji>,
+    reblogs_count: u64,
+    favourites_count: u64,
+    replies_count: u64,
+    url: String,
+    in_reply_to_id: Option<String>,
+    in_reply_to_account_id: Option<String>,
+    reblog: Option<Box<Status>>,
+    // poll: Option<Poll>,
+    // card: Option<PreviewCard>,
+    language: Option<String>,
+    text: Option<String>,
+    edited_at: Option<DateTime<Utc>>,
+    favourited: Option<bool>,
+    reblogged: Option<bool>,
+    muted: Option<bool>,
+    bookmarked: Option<bool>,
+    pinned: Option<bool>,
+    filtered: Option<bool>,
+}