Skip to main content

ScopeObjectMatch

Trait ScopeObjectMatch 

Source
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§

Source

type Input: ?Sized

The type of input expected to validate against the scope.

This will be borrowed, so if you want to match on a &str this type should be str.

Required Methods§

Source

fn matches(&self, input: &Self::Input) -> bool

Check if the input matches against the scope.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§