TileService

Struct TileService 

Source
pub struct TileService<S: SlideSource> { /* private fields */ }
Expand description

Service for generating and caching tiles.

The TileService orchestrates the full tile pipeline:

  1. Validates request parameters
  2. Checks the tile cache for existing results
  3. Fetches the slide from the registry
  4. Reads raw tile data from the slide
  5. Decodes and re-encodes at the requested quality
  6. Caches and returns the result

§Type Parameters

  • S - The slide source type (e.g., S3-based source)

§Example

use wsi_streamer::tile::{TileService, TileRequest};
use wsi_streamer::slide::SlideRegistry;

// Create registry and service
let registry = SlideRegistry::new(source);
let service = TileService::new(registry);

// Request a tile
let request = TileRequest::new("slides/sample.svs", 0, 1, 2);
let response = service.get_tile(request).await?;

println!("Tile size: {} bytes, cache hit: {}", response.data.len(), response.cache_hit);

Implementations§

Source§

impl<S: SlideSource> TileService<S>

Source

pub fn new(registry: SlideRegistry<S>) -> Self

Create a new tile service with default cache settings.

Uses default tile cache capacity (100MB).

Source

pub fn with_shared_registry(registry: Arc<SlideRegistry<S>>) -> Self

Create a new tile service with a shared registry.

This allows multiple services or components to share the same registry.

Source

pub fn with_cache_capacity( registry: SlideRegistry<S>, cache_capacity: usize, ) -> Self

Create a new tile service with custom cache capacity.

§Arguments
  • registry - The slide registry
  • cache_capacity - Maximum tile cache size in bytes
Source

pub async fn get_tile( &self, request: TileRequest, ) -> Result<TileResponse, TileError>

Get a tile, using cache when available.

This is the main entry point for tile requests. It:

  1. Validates the request parameters
  2. Checks the cache for an existing tile
  3. If not cached, fetches from the slide and encodes
  4. Caches and returns the result
§Errors

Returns an error if:

  • The slide cannot be found or opened
  • The level is out of range
  • The tile coordinates are out of bounds
  • The tile data cannot be decoded or encoded
Source

pub async fn generate_tile( &self, request: &TileRequest, quality: u8, ) -> Result<Bytes, TileError>

Generate a tile without caching.

This is useful for one-off requests or when you want to bypass the cache.

Source

pub async fn cache_stats(&self) -> (usize, usize, usize)

Get tile cache statistics.

Returns (current_size, capacity, entry_count).

Source

pub async fn clear_cache(&self)

Clear the tile cache.

Source

pub async fn invalidate_slide(&self, _slide_id: &str)

Invalidate cached tiles for a specific slide.

This removes all cached tiles for the given slide from the tile cache. Note: This is O(n) where n is the number of cached tiles.

Source

pub fn registry(&self) -> &Arc<SlideRegistry<S>>

Get a reference to the underlying registry.

Source

pub async fn generate_thumbnail( &self, slide_id: &str, max_dimension: u32, quality: u8, ) -> Result<TileResponse, TileError>

Generate a thumbnail for a slide.

This finds the lowest resolution level that fits within the requested max dimension and returns a tile or composited image.

§Arguments
  • slide_id - The slide identifier
  • max_dimension - Maximum width or height for the thumbnail
  • quality - JPEG quality (1-100)
§Returns

A JPEG-encoded thumbnail image.

Auto Trait Implementations§

§

impl<S> !Freeze for TileService<S>

§

impl<S> !RefUnwindSafe for TileService<S>

§

impl<S> Send for TileService<S>

§

impl<S> Sync for TileService<S>

§

impl<S> Unpin for TileService<S>

§

impl<S> !UnwindSafe for TileService<S>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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