From 2318a33f9b359ae27b52cd9a19db1f6782d8dae3 Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 1 Aug 2024 22:50:28 +0300 Subject: Upgrade dependencies and fix deprecated functionality I think I managed to not lose any functionality from my dependencies. sqlparser remains unupgraded, but that's mostly because it is only used in one example and it's not worth it to upgrade right now. --- templates-neo/src/mf2.rs | 69 +++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'templates-neo/src') diff --git a/templates-neo/src/mf2.rs b/templates-neo/src/mf2.rs index 8190720..3cf453f 100644 --- a/templates-neo/src/mf2.rs +++ b/templates-neo/src/mf2.rs @@ -64,7 +64,7 @@ impl TryFrom for Card { }); } - let mut props = card.properties.take(); + let mut props = card.properties; let uid = { let uids = props.remove("uid").ok_or(Error::NoUid)?; if let Some(PropertyValue::Url(uid)) = uids.into_iter().take(1).next() { @@ -106,12 +106,12 @@ impl TryFrom for Card { .unwrap_or_default() .into_iter() .next() - .and_then(|v| match v { - PropertyValue::Plain(plain) => Some(Ok(plain)), - other => Some(Err(Error::WrongValueType { + .map(|v| match v { + PropertyValue::Plain(plain) => Ok(plain), + other => Err(Error::WrongValueType { expected: "string", got: other, - })), + }), }) .transpose()?, photo: props @@ -122,10 +122,13 @@ impl TryFrom for Card { .ok_or(Error::MissingProperty("photo")) .and_then(|v| match v { PropertyValue::Url(url) => Ok(Image::Plain(url)), - PropertyValue::Image(image) => Ok(Image::Accessible { - src: image.src, - alt: image.alt, - }), + PropertyValue::Image(image) => match image.alt { + Some(alt) => Ok(Image::Accessible { + src: image.value, + alt, + }), + None => Ok(Image::Plain(image.value)) + }, other => Err(Error::WrongValueType { expected: "string", got: other, @@ -198,7 +201,7 @@ impl Card { for url in urls { let url = String::from(url); ul.list_item(move |li| { - li.push({ Anchor::builder().href(url.clone()).text(url).build() }) + li.push(Anchor::builder().href(url.clone()).text(url).build()) }); } @@ -215,7 +218,7 @@ impl TryFrom for Card { fn try_from(v: PropertyValue) -> Result { match v { - PropertyValue::Item(item) => item.take().try_into(), + PropertyValue::Item(item) => item.try_into(), other => Err(Error::WrongValueType { expected: "h-card", got: other, @@ -229,7 +232,7 @@ pub struct Cite { url: Vec, in_reply_to: Option>, author: Card, - published: Option>, + published: Option, content: Content, } @@ -258,7 +261,7 @@ impl TryFrom for Citation { fn try_from(v: PropertyValue) -> Result { match v { PropertyValue::Url(url) => Ok(Self::Brief(url)), - PropertyValue::Item(item) => Ok(Self::Full(item.take().try_into()?)), + PropertyValue::Item(item) => Ok(Self::Full(item.try_into()?)), other => Err(Error::WrongValueType { expected: "url or h-cite", got: other, @@ -287,7 +290,7 @@ pub struct Entry { author: Card, category: Vec, syndication: Vec, - published: chrono::DateTime, + published: time::OffsetDateTime, content: Content, } @@ -301,7 +304,7 @@ impl TryFrom for Entry { }); } - let mut props = entry.properties.take(); + let mut props = entry.properties; let uid = { let uids = props.remove("uid").ok_or(Error::NoUid)?; if let Some(PropertyValue::Url(uid)) = uids.into_iter().take(1).next() { @@ -369,23 +372,26 @@ impl TryFrom for Entry { .into_iter() .next() .map( - |v| -> Result, Error> { + |v| -> Result { match v { - PropertyValue::Temporal(Temporal::Timestamp(dt)) => { + PropertyValue::Temporal(Temporal::Timestamp(ref dt)) => { // This is incredibly sketchy. let (date, time, offset) = ( - dt.date.clone().unwrap().data, - dt.as_time().unwrap().data.clone(), - dt.as_time().unwrap().offset.unwrap().data, + dt.date.to_owned().ok_or_else(|| Error::WrongValueType { + expected: "timestamp (date, time, offset)", + got: v.clone() + })?.data, + dt.time.to_owned().ok_or_else(|| Error::WrongValueType { + expected: "timestamp (date, time, offset)", + got: v.clone() + })?.data, + dt.offset.to_owned().ok_or_else(|| Error::WrongValueType { + expected: "timestamp (date, time, offset)", + got: v.clone() + })?.data, ); - date.and_time(time) - .and_local_timezone(offset) - .single() - .ok_or_else(|| Error::WrongValueType { - expected: "datetime with timezone", - got: PropertyValue::Temporal(Temporal::Timestamp(dt)), - }) + Ok(date.with_time(time).assume_offset(offset)) } other => Err(Error::WrongValueType { expected: "timestamp", @@ -428,13 +434,10 @@ impl Entry { html::inline_text::Time::builder() .text( self.published - .format("%Y-%m-%d %a %H:%M:%S %z") - .to_string(), + .format(&time::format_description::well_known::Rfc2822) + .unwrap() ) - .date_time(self.published.to_rfc3339_opts( - chrono::SecondsFormat::Secs, - false, - )) + .date_time(self.published.format(&time::format_description::well_known::Rfc3339).unwrap()) .build(), ) }) -- cgit 1.4.1