preset: drain_filter -> extract_if
This commit is contained in:
parent
ab8072c4f7
commit
3735659604
905
Cargo.lock
generated
905
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@ members = [
|
|||
"librashader-capi",
|
||||
"librashader-build-script"
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.metadata.release]
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
//! as input to create a filter chain.
|
||||
//!
|
||||
//! Re-exported as [`librashader::presets`](https://docs.rs/librashader/latest/librashader/presets/index.html).
|
||||
#![feature(drain_filter)]
|
||||
#![feature(extract_if)]
|
||||
|
||||
mod error;
|
||||
mod parse;
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, T
|
|||
|
||||
pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
||||
let textures: Vec<TextureConfig> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Texture { .. }))
|
||||
.extract_if(|f| matches!(*f, Value::Texture { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Texture {
|
||||
name,
|
||||
|
@ -27,7 +27,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
|||
})
|
||||
.collect();
|
||||
let parameters: Vec<ParameterConfig> = values
|
||||
.drain_filter(|f| matches!(*f, Value::Parameter { .. }))
|
||||
.extract_if(|f| matches!(*f, Value::Parameter { .. }))
|
||||
.map(|value| {
|
||||
if let Value::Parameter(name, value) = value {
|
||||
ParameterConfig { name, value }
|
||||
|
@ -64,7 +64,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
|||
|v| matches!(*v, Value::Shader(shader_index, _) if shader_index == shader),
|
||||
) {
|
||||
let shader_values: Vec<Value> = values
|
||||
.drain_filter(|v| v.shader_index() == Some(shader))
|
||||
.extract_if(|v| v.shader_index() == Some(shader))
|
||||
.collect();
|
||||
let scale_type = shader_values.iter().find_map(|f| match f {
|
||||
Value::ScaleType(_, value) => Some(*value),
|
||||
|
|
|
@ -187,7 +187,7 @@ fn load_child_reference_strings(
|
|||
|
||||
let mut new_tokens = do_lex(&reference_contents)?;
|
||||
let new_references: Vec<PathBuf> = new_tokens
|
||||
.drain_filter(|token| *token.key.fragment() == "#reference")
|
||||
.extract_if(|token| *token.key.fragment() == "#reference")
|
||||
.map(|value| PathBuf::from(*value.value.fragment()))
|
||||
.collect();
|
||||
|
||||
|
@ -232,7 +232,7 @@ pub fn parse_values(
|
|||
}
|
||||
|
||||
let references: Vec<PathBuf> = tokens
|
||||
.drain_filter(|token| *token.key.fragment() == "#reference")
|
||||
.extract_if(|token| *token.key.fragment() == "#reference")
|
||||
.map(|value| PathBuf::from(*value.value.fragment()))
|
||||
.collect();
|
||||
|
||||
|
@ -254,7 +254,7 @@ pub fn parse_values(
|
|||
// collect all possible parameter names.
|
||||
let mut parameter_names: Vec<&str> = Vec::new();
|
||||
for (_, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| *token.key.fragment() == "parameters") {
|
||||
for token in tokens.extract_if(|token| *token.key.fragment() == "parameters") {
|
||||
let parameter_name_string: &str = token.value.fragment();
|
||||
for parameter_name in parameter_name_string.split(';') {
|
||||
parameter_names.push(parameter_name);
|
||||
|
@ -265,7 +265,7 @@ pub fn parse_values(
|
|||
// collect all possible texture names.
|
||||
let mut texture_names: Vec<&str> = Vec::new();
|
||||
for (_, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| *token.key.fragment() == "textures") {
|
||||
for token in tokens.extract_if(|token| *token.key.fragment() == "textures") {
|
||||
let texture_name_string: &str = token.value.fragment();
|
||||
for texture_name in texture_name_string.split(';') {
|
||||
texture_names.push(texture_name);
|
||||
|
@ -276,7 +276,7 @@ pub fn parse_values(
|
|||
let mut values = Vec::new();
|
||||
// resolve shader paths.
|
||||
for (path, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| parse_indexed_key("shader", token.key).is_ok()) {
|
||||
for token in tokens.extract_if(|token| parse_indexed_key("shader", token.key).is_ok()) {
|
||||
let (_, index) = parse_indexed_key("shader", token.key).map_err(|e| match e {
|
||||
nom::Err::Error(e) | nom::Err::Failure(e) => {
|
||||
let input: Span = e.input;
|
||||
|
@ -307,7 +307,7 @@ pub fn parse_values(
|
|||
// resolve texture paths
|
||||
let mut textures = Vec::new();
|
||||
for (path, tokens) in all_tokens.iter_mut() {
|
||||
for token in tokens.drain_filter(|token| texture_names.contains(token.key.fragment())) {
|
||||
for token in tokens.extract_if(|token| texture_names.contains(token.key.fragment())) {
|
||||
let mut relative_path = path.to_path_buf();
|
||||
relative_path.push(*token.value.fragment());
|
||||
relative_path
|
||||
|
|
Loading…
Reference in a new issue