#[cfg(feature = "danbooru")]
pub mod danbooru;
#[cfg(feature = "gelbooru")]
pub mod gelbooru;
#[cfg(feature = "rule34")]
pub mod rule34;
#[cfg(feature = "safebooru")]
pub mod safebooru;
pub trait Post {
fn id(&self) -> u32;
fn width(&self) -> u32;
fn height(&self) -> u32;
fn file_url(&self) -> Option<&str>;
fn tags(&self) -> &str;
fn score(&self) -> Option<i32>;
fn md5(&self) -> Option<&str>;
fn source(&self) -> Option<&str>;
}
#[cfg(feature = "danbooru")]
impl Post for danbooru::DanbooruPost {
fn id(&self) -> u32 {
self.id
}
fn width(&self) -> u32 {
self.image_width
}
fn height(&self) -> u32 {
self.image_height
}
fn file_url(&self) -> Option<&str> {
self.file_url.as_deref()
}
fn tags(&self) -> &str {
&self.tag_string
}
fn score(&self) -> Option<i32> {
Some(self.score)
}
fn md5(&self) -> Option<&str> {
self.md5.as_deref()
}
fn source(&self) -> Option<&str> {
if self.source.is_empty() {
None
} else {
Some(&self.source)
}
}
}
#[cfg(feature = "gelbooru")]
impl Post for gelbooru::GelbooruPost {
fn id(&self) -> u32 {
self.id
}
fn width(&self) -> u32 {
self.width
}
fn height(&self) -> u32 {
self.height
}
fn file_url(&self) -> Option<&str> {
Some(&self.file_url)
}
fn tags(&self) -> &str {
&self.tags
}
fn score(&self) -> Option<i32> {
Some(self.score as i32)
}
fn md5(&self) -> Option<&str> {
Some(&self.md5)
}
fn source(&self) -> Option<&str> {
if self.source.is_empty() {
None
} else {
Some(&self.source)
}
}
}
#[cfg(feature = "safebooru")]
impl Post for safebooru::SafebooruPost {
fn id(&self) -> u32 {
self.id
}
fn width(&self) -> u32 {
self.width
}
fn height(&self) -> u32 {
self.height
}
fn file_url(&self) -> Option<&str> {
Some(&self.file_url)
}
fn tags(&self) -> &str {
&self.tags
}
fn score(&self) -> Option<i32> {
self.score.map(|s| s as i32)
}
fn md5(&self) -> Option<&str> {
Some(&self.hash)
}
fn source(&self) -> Option<&str> {
if self.source.is_empty() {
None
} else {
Some(&self.source)
}
}
}
#[cfg(feature = "rule34")]
impl Post for rule34::Rule34Post {
fn id(&self) -> u32 {
self.id
}
fn width(&self) -> u32 {
self.width
}
fn height(&self) -> u32 {
self.height
}
fn file_url(&self) -> Option<&str> {
Some(&self.file_url)
}
fn tags(&self) -> &str {
&self.tags
}
fn score(&self) -> Option<i32> {
Some(self.score)
}
fn md5(&self) -> Option<&str> {
if self.hash.is_empty() {
None
} else {
Some(&self.hash)
}
}
fn source(&self) -> Option<&str> {
if self.source.is_empty() {
None
} else {
Some(&self.source)
}
}
}