mirror of
https://codeberg.org/postscriptum/snac2nex.git
synced 2026-03-31 21:25:28 +00:00
unify post type member name
This commit is contained in:
parent
abbb7f6986
commit
3aba70cb31
2 changed files with 6 additions and 6 deletions
|
|
@ -4,7 +4,7 @@ mod tag;
|
||||||
|
|
||||||
use attachment::Attachment;
|
use attachment::Attachment;
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use ptype::Type;
|
use ptype::Ptype;
|
||||||
use serde::{Deserialize, de::Error};
|
use serde::{Deserialize, de::Error};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tag::Tag;
|
use tag::Tag;
|
||||||
|
|
@ -13,7 +13,7 @@ use tag::Tag;
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
#[serde(rename = "type", deserialize_with = "ptype")]
|
#[serde(rename = "type", deserialize_with = "ptype")]
|
||||||
pub ptype: Type,
|
pub ptype: Ptype,
|
||||||
pub attachment: Option<Vec<Attachment>>,
|
pub attachment: Option<Vec<Attachment>>,
|
||||||
pub id: String,
|
pub id: String,
|
||||||
#[serde(default, deserialize_with = "time")]
|
#[serde(default, deserialize_with = "time")]
|
||||||
|
|
@ -27,13 +27,13 @@ pub struct Post {
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
pub fn is_note(&self) -> bool {
|
pub fn is_note(&self) -> bool {
|
||||||
matches!(self.ptype, Type::Note)
|
matches!(self.ptype, Ptype::Note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ptype<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Type, D::Error> {
|
fn ptype<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Ptype, D::Error> {
|
||||||
if String::deserialize(d)?.to_lowercase() == "note" {
|
if String::deserialize(d)?.to_lowercase() == "note" {
|
||||||
return Ok(Type::Note);
|
return Ok(Ptype::Note);
|
||||||
}
|
}
|
||||||
Err(D::Error::custom("Invalid post type"))
|
Err(D::Error::custom("Invalid post type"))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Type {
|
pub enum Ptype {
|
||||||
Note,
|
Note,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue