PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Move the descriptor helpers next to int() so the sibling smart-filter PRs share them
David Mannc2dbd974ebbd
diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rsindex cbffc27c5..99048cdd7 100644--- a/crates/io/src/smart_map.rs+++ b/crates/io/src/smart_map.rs@@ -183,6 +183,20 @@ fn int(d: &Descriptor, key: &str) -> Option<i32> {}}+/// `Some(())` when every setting of `f` is one of `keys`: a filter with a setting we don't write+/// back stays verbatim instead of losing it on save.+fn only_keys(f: &Descriptor, keys: &[&str]) -> Option<()> {+ f.items.iter().all(|(k, _)| keys.iter().any(|key| k.is(key))).then_some(())+}++/// The value of the enum `key` when its type is `type_id` (a mistyped enum is not modelled).+fn typed_enum<'a>(f: &'a Descriptor, key: &str, type_id: &str) -> Option<&'a [u8]> {+ match f.get(key)? {+ Value::Enumerated { type_id: t, value } if t.is(type_id) => Some(value.as_bytes()),+ _ => None,+ }+}+fn channel_key(d: &Descriptor) -> Option<&'static str> {let Some(Value::Reference(items)) = d.get("Chnl") else { return None };let Some(ReferenceItem::Enumerated { value, .. }) = items.first() else { return None };@@ -273,20 +287,6 @@ fn int_in(v: Option<i32>, (lo, hi): (i32, i32)) -> Option<i32> {v.filter(|v| (lo..=hi).contains(v))}-/// `Some(())` when every setting of `f` is one of `keys`: a filter with a setting we don't write-/// back stays verbatim instead of losing it on save.-fn only_keys(f: &Descriptor, keys: &[&str]) -> Option<()> {- f.items.iter().all(|(k, _)| keys.iter().any(|key| k.is(key))).then_some(())-}--/// The value of the enum `key` when its type is `type_id` (a mistyped enum is not modelled).-fn typed_enum<'a>(f: &'a Descriptor, key: &str, type_id: &str) -> Option<&'a [u8]> {- match f.get(key)? {- Value::Enumerated { type_id: t, value } if t.is(type_id) => Some(value.as_bytes()),- _ => None,- }-}-/// `filter.other.custom` params for a `Cstm` filter: `Mtrx` is 25 longs, row-major 5 × 5. Values/// outside Photoshop's ranges are not modelled (the filter stays verbatim).fn custom_params(f: &Descriptor) -> Option<J> {