pub trait ScopeObjectMatch: ScopeObject {
type Input: ?Sized;
// Required method
fn matches(&self, input: &Self::Input) -> bool;
}Expand description
A ScopeObject whose validation can be represented as a bool.
§Example
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Scope {
Domain(Url),
StartsWith(String),
}
impl ScopeObjectMatch for Scope {
type Input = str;
fn matches(&self, input: &str) -> bool {
match self {
Scope::Domain(url) => {
let parsed: Url = match input.parse() {
Ok(parsed) => parsed,
Err(_) => return false,
};
let domain = parsed.domain();
domain.is_some() && domain == url.domain()
}
Scope::StartsWith(start) => input.starts_with(start),
}
}
}Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.