1use crate::error::FontLoadingError;
14use crate::family_handle::FamilyHandle;
15use crate::font::Font;
16use crate::handle::Handle;
17use crate::loader::Loader;
18
19#[derive(Debug)]
21pub struct Family<F = Font>
22where
23 F: Loader,
24{
25 fonts: Vec<F>,
26}
27
28impl<F> Family<F>
29where
30 F: Loader,
31{
32 pub(crate) fn from_font_handles<'a, I>(font_handles: I) -> Result<Family<F>, FontLoadingError>
33 where
34 I: Iterator<Item = &'a Handle>,
35 {
36 let mut fonts = vec![];
37 for font_handle in font_handles {
38 fonts.push(F::from_handle(font_handle)?)
39 }
40 Ok(Family { fonts })
41 }
42
43 #[inline]
44 pub(crate) fn from_handle(family_handle: &FamilyHandle) -> Result<Family<F>, FontLoadingError> {
45 Family::from_font_handles(family_handle.fonts.iter())
46 }
47
48 #[inline]
50 pub fn fonts(&self) -> &[F] {
51 &self.fonts
52 }
53
54 #[inline]
56 pub fn is_empty(&self) -> bool {
57 self.fonts.is_empty()
58 }
59}