-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lacking appropriate watchdog changes for now, and probably other things. Asset extraction from the chunkloader ("deep") also remains unfixed.
- Loading branch information
Showing
6 changed files
with
78 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
use crate::discord::{FeAsset, FeAssetType, RootScript}; | ||
|
||
pub trait AssetsExt<'a, I> { | ||
pub trait AssetsExt<'source, Source: ?Sized> { | ||
// We can't use "return position impl trait in traits" here, so we're forced | ||
// to either box or implement our own iterator type. I can't be bothered to | ||
// write a new iterator type at the moment so we'll just box. | ||
fn filter_by_type(self, typ: FeAssetType) -> Box<dyn Iterator<Item = &'a FeAsset> + 'a + Send>; | ||
fn filter_by_type( | ||
self, | ||
typ: FeAssetType, | ||
) -> Box<dyn Iterator<Item = &'source FeAsset> + 'source + Send>; | ||
|
||
fn find_root_script(self, root_script_type: RootScript) -> Option<&'a FeAsset> | ||
fn find_root_script(self, root_script_type: RootScript) -> Option<&'source FeAsset> | ||
where | ||
Self: Sized, | ||
{ | ||
self.filter_by_type(FeAssetType::Js) | ||
.nth(root_script_type.assumed_index()) | ||
let scripts = self.filter_by_type(FeAssetType::Js).collect::<Vec<_>>(); | ||
|
||
root_script_type | ||
.assumed_index_within_scripts(scripts.len()) | ||
.and_then(|index| scripts.into_iter().nth(index)) | ||
} | ||
} | ||
|
||
impl<'a, I: Iterator<Item = &'a FeAsset> + 'a + Send> AssetsExt<'a, I> for I { | ||
fn filter_by_type(self, typ: FeAssetType) -> Box<dyn Iterator<Item = &'a FeAsset> + 'a + Send> { | ||
Box::new(self.filter(move |asset| asset.typ == typ)) | ||
// Implement the convenience extension on any reference to a source, where said | ||
// reference can be turned into an iterator yielding references to assets within | ||
// the source. The source doesn't have to be sized, so we can use slices with | ||
// it, which are notably unsized when not behind some indirection (e.g. a | ||
// reference). | ||
impl<'source, Source: ?Sized> AssetsExt<'source, Source> for &'source Source | ||
where | ||
&'source Source: IntoIterator<Item = &'source FeAsset> + Send, | ||
<&'source Source as IntoIterator>::IntoIter: Send + 'source, | ||
{ | ||
fn filter_by_type( | ||
self, | ||
typ: FeAssetType, | ||
) -> Box<dyn Iterator<Item = &'source FeAsset> + 'source + Send> { | ||
Box::new(self.into_iter().filter(move |asset| asset.typ == typ)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters