Skip to main content

mln_engine/storage/
resource_transform.rs

1use std::sync::Arc;
2
3use crate::storage::resource::Kind;
4use crate::storage::response::ResourceError;
5
6/// What a resource transform answers: the URL to load instead, or the error
7/// to fail the request with. A failed request is never sent. When the
8/// error's reason allows a retry, the retry calls the transform again.
9pub type TransformResult = Result<String, ResourceError>;
10
11/// The callback a resource transform answers through, once.
12pub type FinishedCallback = Box<dyn FnOnce(TransformResult) + Send>;
13
14/// Rewrites request URLs (asynchronously) before the online file source
15/// requests them, or fails the requests. It gets the resource's kind and
16/// URL, and runs on the online file source's thread, hence `Send + Sync`.
17pub type ResourceTransform = Arc<dyn Fn(Kind, &str, FinishedCallback) + Send + Sync>;