Skip to main content

SimbadResolver

Struct SimbadResolver 

Source
pub struct SimbadResolver<R: Resolver> { /* private fields */ }
Expand description

The cache-first resolver facade.

Generic over any Resolver backend (TAP, Sesame, offline, fake); the cache backend is chosen at construction via CacheBackend and type-erased, so the facade type does not carry it.

This example uses crate::OfflineResolver and seeds the cache directly, so it runs without a network call — the cache-first lookup below never reaches the resolver.

use simbad_resolver::{
    AliasKind, CacheBackend, OfflineResolver, ObjectType, Resolution, ResolvedAlias,
    ResolvedIdentity, ResolverConfig, SimbadResolver, TargetSource,
};

let config = ResolverConfig::new("guide.example");
let namespace = config.namespace;
let facade = SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, config)?;

let m31 = ResolvedIdentity {
    simbad_oid: Some(1_575_544),
    primary_designation: "M 31".to_owned(),
    common_name: Some("Andromeda Galaxy".to_owned()),
    object_type: ObjectType::Galaxy,
    otype_raw: "G".to_owned(),
    ra_deg: 10.684_708,
    dec_deg: 41.268_75,
    v_mag: Some(3.44),
    aliases: vec![ResolvedAlias::new("M 31", AliasKind::Designation)],
    source: TargetSource::Seed,
};
facade.cache().upsert(&m31, &namespace).await?;

match facade.resolve("M31").await? {
    Resolution::Resolved(target) => assert_eq!(target.primary_designation, "M 31"),
    Resolution::Unresolved { .. } => unreachable!("seeded above"),
}

Implementations§

Source§

impl<R: Resolver> SimbadResolver<R>

Source

pub fn new( resolver: R, cache: CacheBackend, config: ResolverConfig, ) -> Result<Self, Error>

Construct a facade from a resolver, a CacheBackend, and config.

§Errors

Returns Error if a built-in (CacheBackend::InMemory / CacheBackend::File) store cannot be opened or initialised. CacheBackend::Custom never fails here.

use simbad_resolver::{CacheBackend, OfflineResolver, ResolverConfig, SimbadResolver};

let facade = SimbadResolver::new(
    OfflineResolver,
    CacheBackend::InMemory,
    ResolverConfig::new("my-app.targets"),
)?;
Source

pub fn cache(&self) -> &dyn Cache

Borrow the underlying cache (e.g. for seeding or enumeration).

use simbad_resolver::{CacheBackend, OfflineResolver, ResolverConfig, SimbadResolver};

let facade =
    SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, ResolverConfig::new("x"))?;
assert!(facade.cache().list().await?.is_empty(), "freshly constructed cache is empty");
Source

pub fn resolver(&self) -> &R

Borrow the underlying resolver (e.g. to inspect a fake’s call count in tests).

use simbad_resolver::{CacheBackend, OfflineResolver, ResolverConfig, SimbadResolver};

let facade =
    SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, ResolverConfig::new("x"))?;
let _resolver: &OfflineResolver = facade.resolver();
Source

pub async fn search( &self, query: &str, limit: usize, ) -> Result<Vec<SearchHit>, Error>

Local, network-free typeahead search over cached aliases.

Returns exact/prefix/substring matches (see Cache::search). When fuzzy matching is enabled via ResolverConfig::with_fuzzy and fewer than limit of those are found, the remaining slots are filled with token-set similarity matches (crate::RANK_FUZZY), best score first. This fuzzy matching does not affect Self::resolve, which stays exact-normalized.

This example seeds the cache directly (no resolver call needed) then searches it — see the guide for the full walkthrough.

use simbad_resolver::{
    AliasKind, CacheBackend, ObjectType, OfflineResolver, ResolvedAlias, ResolvedIdentity,
    ResolverConfig, SimbadResolver, TargetSource,
};

let config = ResolverConfig::new("example");
let namespace = config.namespace;
let facade = SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, config)?;
let m31 = ResolvedIdentity {
    simbad_oid: Some(1_575_544),
    primary_designation: "M 31".to_owned(),
    common_name: None,
    object_type: ObjectType::Galaxy,
    otype_raw: "G".to_owned(),
    ra_deg: 10.684_708,
    dec_deg: 41.268_75,
    v_mag: Some(3.44),
    aliases: vec![ResolvedAlias::new("M 31", AliasKind::Designation)],
    source: TargetSource::Seed,
};
facade.cache().upsert(&m31, &namespace).await?;

let hits = facade.search("M 3", 5).await?; // prefix match
assert_eq!(hits[0].target.primary_designation, "M 31");
Source

pub async fn resolve(&self, query: &str) -> Result<Resolution, Error>

Cache-first resolve. On a cache miss and when online is enabled, consult the resolver, persist the result, and return it; otherwise return a typed Resolution::Unresolved. Caldwell designations (C n) are translated to their standard designation first and the original C n bound as an alias.

See the struct-level example for a seeded, network-free walkthrough, or crate::guide for the full task-oriented guide.

use simbad_resolver::{CacheBackend, OfflineResolver, Resolution, ResolverConfig, SimbadResolver};

let facade =
    SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, ResolverConfig::new("x"))?;
// Nothing cached and no network reachable (`OfflineResolver`): unresolved, not an error.
match facade.resolve("M31").await? {
    Resolution::Resolved(_) => unreachable!("cache is empty"),
    Resolution::Unresolved { query, .. } => assert_eq!(query, "M31"),
}
Source

pub async fn apply_override( &self, target_id: Uuid, alias: &str, ) -> Result<Option<CachedTarget>, Error>

Bind a chosen canonical target as an authoritative user override, adding alias and making the row sticky (source = user-override). Returns the updated target, or None if target_id is unknown.

See crate::guide for a full “pin a target” walkthrough.

use simbad_resolver::{
    AliasKind, CacheBackend, ObjectType, OfflineResolver, ResolvedAlias, ResolvedIdentity,
    ResolverConfig, SimbadResolver, TargetSource,
};

let config = ResolverConfig::new("example");
let namespace = config.namespace;
let facade = SimbadResolver::new(OfflineResolver, CacheBackend::InMemory, config)?;
let m31 = ResolvedIdentity {
    simbad_oid: Some(1_575_544),
    primary_designation: "M 31".to_owned(),
    common_name: None,
    object_type: ObjectType::Galaxy,
    otype_raw: "G".to_owned(),
    ra_deg: 10.684_708,
    dec_deg: 41.268_75,
    v_mag: Some(3.44),
    aliases: vec![ResolvedAlias::new("M 31", AliasKind::Designation)],
    source: TargetSource::Seed,
};
let (id, _) = facade.cache().upsert(&m31, &namespace).await?;

let pinned = facade.apply_override(id, "My Andromeda").await?.expect("id is known");
assert_eq!(pinned.source, TargetSource::UserOverride);
assert!(pinned.aliases.iter().any(|a| a.alias == "My Andromeda"));

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for SimbadResolver<R>

§

impl<R> !UnwindSafe for SimbadResolver<R>

§

impl<R> Freeze for SimbadResolver<R>
where R: Freeze,

§

impl<R> Send for SimbadResolver<R>

§

impl<R> Sync for SimbadResolver<R>

§

impl<R> Unpin for SimbadResolver<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for SimbadResolver<R>
where R: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more