1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Methods Swift and Kotlin call on the types (feature `uniffi`), where
//! the Rust method borrows and UniFFI needs an owned value: the same
//! answer. `Item`'s carry `item_` in their exported names: Swift refuses
//! a property beside a method of the same name, SwiftUI lists need
//! `var id`, and UniFFI's rename table does not reach an enum's methods.
use crate::{
Artwork, ArtworkKind, Item, MediaId, PlaybackState, QuotaOf, RatingScale, RatingSource,
};
#[uniffi::export]
impl RatingSource {
/// How its ratings read: a percentage, or out of 10.
#[uniffi::method(name = "rating_scale")]
pub fn scale_owned(&self) -> RatingScale {
self.scale()
}
/// A rating of `tenths` as the provider shows it: "92%" or "7.9".
#[uniffi::method(name = "rating_display")]
pub fn display_owned(&self, tenths: u16) -> String {
self.display(tenths)
}
}
#[uniffi::export]
impl Item {
/// Its id, whatever kind it is: what a list keys its rows by.
#[uniffi::method(name = "item_id")]
pub fn id_owned(&self) -> MediaId {
self.id().clone()
}
/// Its own name: a film's, an episode's or a track's title; an
/// artist's name.
#[uniffi::method(name = "item_title")]
pub fn title_owned(&self) -> String {
self.title().to_owned()
}
/// Its artwork, whatever kind it is.
#[uniffi::method(name = "item_artwork")]
pub fn artwork_owned(&self) -> Vec<Artwork> {
self.artwork().to_vec()
}
/// Its length, for the kinds that play.
#[uniffi::method(name = "item_duration")]
pub fn duration_owned(&self) -> Option<std::time::Duration> {
self.duration()
}
/// Its first poster.
pub fn poster(&self) -> Option<Artwork> {
self.artwork_of(ArtworkKind::Poster).cloned()
}
/// Its first background.
pub fn background(&self) -> Option<Artwork> {
self.artwork_of(ArtworkKind::Background).cloned()
}
/// Its first thumbnail.
pub fn thumb(&self) -> Option<Artwork> {
self.artwork_of(ArtworkKind::Thumb).cloned()
}
/// The user's progress on a film, an episode or a track; `None` for
/// the kinds that do not play themselves.
#[uniffi::method(name = "item_playback")]
pub fn playback_owned(&self) -> Option<PlaybackState> {
self.playback().cloned()
}
}
/// The server id of the paired server a federated item is on; `None`
/// for the server's own ([`MediaId::origin`]).
#[uniffi::export]
pub fn media_origin(id: MediaId) -> Option<String> {
id.origin().map(str::to_owned)
}
#[uniffi::export]
impl QuotaOf {
/// It is the user's own daily limit, not the server's account at the
/// site: "You've reached your limit" rather than "No one can".
pub fn is_user(&self) -> bool {
*self == QuotaOf::User
}
}