@ -1,6 +1,4 @@
//! Module containing everything related to media attachements.
//! Module containing everything related to media attachements.
use serde ::{ Deserialize , Deserializer } ;
use super ::Empty ;
/// A struct representing a media attachment.
/// A struct representing a media attachment.
#[ derive(Debug, Clone, Deserialize) ]
#[ derive(Debug, Clone, Deserialize) ]
@ -20,35 +18,18 @@ pub struct Attachment {
/// (only present on local images)
/// (only present on local images)
pub text_url : Option < String > ,
pub text_url : Option < String > ,
/// Meta information about the attachment.
/// Meta information about the attachment.
#[ serde(deserialize_with= " empty_as_none " ) ]
pub meta : Option < Meta > ,
pub meta : Option < Meta > ,
/// Noop will be removed.
/// Noop will be removed.
pub description : Option < String > ,
pub description : Option < String > ,
}
}
fn empty_as_none < ' de , D : Deserializer < ' de > > ( val : D )
-> Result < Option < Meta > , D ::Error >
{
#[ derive(Deserialize) ]
#[ serde(untagged) ]
enum EmptyOrMeta {
Empty ( Empty ) ,
Meta ( Meta ) ,
}
Ok ( match EmptyOrMeta ::deserialize ( val ) ? {
EmptyOrMeta ::Empty ( _ ) = > None ,
EmptyOrMeta ::Meta ( m ) = > Some ( m ) ,
} )
}
/// Information about the attachment itself.
/// Information about the attachment itself.
#[ derive(Debug, Deserialize, Clone) ]
#[ derive(Debug, Deserialize, Clone) ]
pub struct Meta {
pub struct Meta {
/// Original version.
/// Original version.
original : ImageDetails ,
pub original : Option < ImageDetails > ,
/// Smaller version.
/// Smaller version.
small : ImageDetails ,
pub small : Option < ImageDetails > ,
}
}
/// Dimensions of an attachement.
/// Dimensions of an attachement.