
# Objective - Bevy currently has lot of invalid intra-doc links, let's fix them! - Also make CI test them, to avoid future regressions. - Helps with #1983 (but doesn't fix it, as there could still be explicit links to docs.rs that are broken) ## Solution - Make `cargo r -p ci -- doc-check` check fail on warnings (could also be changed to just some specific lints) - Manually fix all the warnings (note that in some cases it was unclear to me what the fix should have been, I'll try to highlight them in a self-review)
41 lines
1.1 KiB
Rust
41 lines
1.1 KiB
Rust
use crate::Font;
|
|
use bevy_asset::{io::Reader, AssetLoader, LoadContext};
|
|
use thiserror::Error;
|
|
|
|
#[derive(Default)]
|
|
/// An [`AssetLoader`] for [`Font`]s, for use by the [`AssetServer`](bevy_asset::AssetServer)
|
|
pub struct FontLoader;
|
|
|
|
/// Possible errors that can be produced by [`FontLoader`]
|
|
#[non_exhaustive]
|
|
#[derive(Debug, Error)]
|
|
pub enum FontLoaderError {
|
|
/// The contents that could not be parsed
|
|
#[error(transparent)]
|
|
Content(#[from] cosmic_text::ttf_parser::FaceParsingError),
|
|
/// An [IO](std::io) Error
|
|
#[error(transparent)]
|
|
Io(#[from] std::io::Error),
|
|
}
|
|
|
|
impl AssetLoader for FontLoader {
|
|
type Asset = Font;
|
|
type Settings = ();
|
|
type Error = FontLoaderError;
|
|
async fn load<'a>(
|
|
&'a self,
|
|
reader: &'a mut dyn Reader,
|
|
_settings: &'a (),
|
|
_load_context: &'a mut LoadContext<'_>,
|
|
) -> Result<Font, Self::Error> {
|
|
let mut bytes = Vec::new();
|
|
reader.read_to_end(&mut bytes).await?;
|
|
let font = Font::try_from_bytes(bytes)?;
|
|
Ok(font)
|
|
}
|
|
|
|
fn extensions(&self) -> &[&str] {
|
|
&["ttf", "otf"]
|
|
}
|
|
}
|