fetcher.rs (1118B)
1 use async_trait::async_trait; 2 use fluent_fallback::types::ResourceId; 3 use std::io; 4 5 /// The users of [`FileSource`] implement this trait to provide loading of 6 /// resources, returning the contents of a resource as a 7 /// `String`. [`FileSource`] handles the conversion from string representation 8 /// into `FluentResource`. 9 /// 10 /// [`FileSource`]: source/struct.FileSource.html 11 #[async_trait(?Send)] 12 pub trait FileFetcher { 13 /// Return the `String` representation for `path`. This version is 14 /// blocking. 15 /// 16 /// See [`fetch`](#tymethod.fetch). 17 fn fetch_sync(&self, resource_id: &ResourceId) -> io::Result<String>; 18 19 /// Return the `String` representation for `path`. 20 /// 21 /// On success, returns `Poll::Ready(Ok(..))`. 22 /// 23 /// If no resource is available to be fetched, the method returns 24 /// `Poll::Pending` and arranges for the current task (via 25 /// `cx.waker().wake_by_ref()`) to receive a notification when the resource 26 /// is available. 27 /// 28 /// See [`fetch_sync`](#tymethod.fetch_sync) 29 async fn fetch(&self, path: &ResourceId) -> io::Result<String>; 30 }