#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SearchParameter {
pub url: &'static str,
pub name: &'static str,
pub code: &'static str,
pub base: &'static [&'static str],
pub r#type: SearchParamType,
pub expression: Option<&'static str>,
pub experimental: bool,
}
#[derive(Debug)]
pub struct SearchParameters {
pub parameters: &'static [SearchParameter],
pub by_resource: &'static [(&'static str, &'static str, usize)],
}
impl SearchParameters {
#[must_use]
pub fn of(&self, resource_type: &str, code: &str) -> Option<&SearchParameter> {
let found = self
.by_resource
.binary_search_by(|(entry_type, entry_code, _)| {
(*entry_type, *entry_code).cmp(&(resource_type, code))
})
.ok()?;
let (_, _, index) = self.by_resource.get(found)?;
self.parameters.get(*index)
}
#[must_use]
pub fn by_url(&self, url: &str) -> Option<&SearchParameter> {
let found = self
.parameters
.binary_search_by(|parameter| parameter.url.cmp(url))
.ok()?;
self.parameters.get(found)
}
pub fn of_type<'a>(
&'a self,
resource_type: &'a str,
) -> impl Iterator<Item = &'a SearchParameter> + 'a {
self.by_resource
.iter()
.filter(move |(entry_type, _, _)| *entry_type == resource_type)
.filter_map(|(_, _, index)| self.parameters.get(*index))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SearchParamType {
Composite,
Date,
Number,
Quantity,
Reference,
Resource,
Special,
String,
Token,
Uri,
}
impl SearchParamType {
#[must_use]
pub const fn code(self) -> &'static str {
match self {
Self::Composite => "composite",
Self::Date => "date",
Self::Number => "number",
Self::Quantity => "quantity",
Self::Reference => "reference",
Self::Resource => "resource",
Self::Special => "special",
Self::String => "string",
Self::Token => "token",
Self::Uri => "uri",
}
}
}