
# Objective - Fixes #12976 ## Solution This one is a doozy. - Run `cargo +beta clippy --workspace --all-targets --all-features` and fix all issues - This includes: - Moving inner attributes to be outer attributes, when the item in question has both inner and outer attributes - Use `ptr::from_ref` in more scenarios - Extend the valid idents list used by `clippy:doc_markdown` with more names - Use `Clone::clone_from` when possible - Remove redundant `ron` import - Add backticks to **so many** identifiers and items - I'm sorry whoever has to review this --- ## Changelog - Added links to more identifiers in documentation.
39 lines
1008 B
Rust
39 lines
1008 B
Rust
use crate::Font;
|
|
use bevy_asset::{io::Reader, AssetLoader, AsyncReadExt, LoadContext};
|
|
use thiserror::Error;
|
|
|
|
#[derive(Default)]
|
|
pub struct FontLoader;
|
|
|
|
/// Possible errors that can be produced by [`FontLoader`]
|
|
#[non_exhaustive]
|
|
#[derive(Debug, Error)]
|
|
pub enum FontLoaderError {
|
|
/// An [IO](std::io) Error
|
|
#[error(transparent)]
|
|
Io(#[from] std::io::Error),
|
|
/// An [`InvalidFont`](ab_glyph::InvalidFont) Error
|
|
#[error(transparent)]
|
|
FontInvalid(#[from] ab_glyph::InvalidFont),
|
|
}
|
|
|
|
impl AssetLoader for FontLoader {
|
|
type Asset = Font;
|
|
type Settings = ();
|
|
type Error = FontLoaderError;
|
|
async fn load<'a>(
|
|
&'a self,
|
|
reader: &'a mut Reader<'_>,
|
|
_settings: &'a (),
|
|
_load_context: &'a mut LoadContext<'_>,
|
|
) -> Result<Font, Self::Error> {
|
|
let mut bytes = Vec::new();
|
|
reader.read_to_end(&mut bytes).await?;
|
|
Ok(Font::try_from_bytes(bytes)?)
|
|
}
|
|
|
|
fn extensions(&self) -> &[&str] {
|
|
&["ttf", "otf"]
|
|
}
|
|
}
|