Skip to main content

FetchAndUpdate

Trait FetchAndUpdate 

Source
pub trait FetchAndUpdate: Sized {
    type Item: Serialize + DeserializeOwned + Timestamped + Clone + Send + Sync + 'static;

    // Required method
    async fn fetch_since(self, max_ts: Option<u32>) -> Result<Vec<Self::Item>>;

    // Provided method
    async fn fetch_and_update(self, file_path: &str) -> Result<usize> { ... }
}
Expand description

Extension trait providing fetch_and_update and fetch_and_update_sqlite for request builders whose items carry a timestamp.

Implementations decide how to apply the timestamp - either as a server-side API filter (e.g. since) or as an in-memory filter after fetching everything.

Required Associated Types§

Source

type Item: Serialize + DeserializeOwned + Timestamped + Clone + Send + Sync + 'static

The item type produced by this builder.

Required Methods§

Source

async fn fetch_since(self, max_ts: Option<u32>) -> Result<Vec<Self::Item>>

Fetch items that are newer than max_ts, or all items if None.

Each builder implements this to decide whether to apply the filter on the API side (more efficient) or in memory after fetching.

Provided Methods§

Source

async fn fetch_and_update(self, file_path: &str) -> Result<usize>

Fetch only items newer than the most recent entry in an existing file and prepend them to it. Creates the file if it does not exist.

The latest timestamp is read from a sidecar file, falling back to scanning the JSON file itself. CSV and NDJSON files rely exclusively on the sidecar.

§Errors

Returns an error if the HTTP request fails, the response cannot be parsed, or the file cannot be read or written.

§Returns
  • Result<usize> - Number of new items prepended

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§