Skip to content

Commit

Permalink
Implement DirLoadable for OnceInitCell when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Jul 5, 2024
1 parent 051336a commit c4c9bd1
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/utils/cell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AnyCache, BoxedError, Compound, SharedString, Storable};
use crate::{asset::DirLoadable, AnyCache, BoxedError, Compound, SharedString, Storable};
use once_cell::sync::OnceCell;
use std::{cell::UnsafeCell, fmt, mem::ManuallyDrop};

Expand Down Expand Up @@ -261,6 +261,34 @@ impl<U: Compound, T: Storable> Compound for OnceInitCell<Option<U>, T> {
const HOT_RELOADED: bool = U::HOT_RELOADED;
}

impl<U: DirLoadable, T: Storable> DirLoadable for OnceInitCell<U, T> {
fn select_ids(cache: AnyCache, id: &SharedString) -> std::io::Result<Vec<SharedString>> {
U::select_ids(cache, id)
}

fn sub_directories(
cache: AnyCache,
id: &SharedString,
f: impl FnMut(&str),
) -> std::io::Result<()> {
U::sub_directories(cache, id, f)
}
}

impl<U: DirLoadable, T: Storable> DirLoadable for OnceInitCell<Option<U>, T> {
fn select_ids(cache: AnyCache, id: &SharedString) -> std::io::Result<Vec<SharedString>> {
U::select_ids(cache, id)
}

fn sub_directories(
cache: AnyCache,
id: &SharedString,
f: impl FnMut(&str),
) -> std::io::Result<()> {
U::sub_directories(cache, id, f)
}
}

/// Like `drop` but cold to keep this out of the happy path
#[cold]
fn drop_cold<T>(_x: T) {}

0 comments on commit c4c9bd1

Please sign in to comment.