File size: 1,549 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
use std::{collections::BTreeMap, hash::Hash, ops::DerefMut};
use serde::{Deserialize, Serialize};
use turbo_tasks::{NonLocalValue, TaskInput, trace::TraceRawVcs};
use super::ContentSourceDataFilter;
/// A parsed query string from a http request
#[derive(
Clone, Debug, PartialEq, Eq, Default, Hash, TraceRawVcs, Serialize, Deserialize, NonLocalValue,
)]
#[serde(transparent)]
pub struct Query(BTreeMap<String, QueryValue>);
// This type contains no VCs so the default implementation works.
// Query is also recursive through QueryValue so the derive macro doesnt work
impl TaskInput for Query {
fn is_transient(&self) -> bool {
false
}
}
impl Query {
pub fn filter_with(&mut self, filter: &ContentSourceDataFilter) {
match filter {
ContentSourceDataFilter::All => {
// fast path without iterating query
}
_ => self.0.retain(|k, _| filter.contains(k)),
}
}
}
impl std::ops::Deref for Query {
type Target = BTreeMap<String, QueryValue>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for Query {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, TraceRawVcs, Serialize, Deserialize, NonLocalValue)]
#[serde(untagged)]
pub enum QueryValue {
/// Simple string value, might be an empty string when there is no value
String(String),
/// An array of values
Array(Vec<QueryValue>),
/// A nested structure
Nested(Query),
}
|