pub trait ContentProvider {
// Required method
fn fetch(&self, key: &str) -> ProviderResult<Vec<u8>>;
// Provided methods
fn fetch_string(&self, key: &str) -> ProviderResult<String> { ... }
fn contains(&self, key: &str) -> bool { ... }
}Expand description
Abstract content store consumed by the renderer.
Keys are stable, URL-safe path-shaped strings (content/posts/foo.md,
templates/post.html). Adapters MAY mangle keys internally (KV
namespace prefixing, slash-to-underscore, etc.) but MUST present the
canonical key surface to the renderer.
§Object safety
The trait is intentionally object-safe so renderer code can hold a
&dyn ContentProvider without monomorphising every site that uses
a different adapter.
Required Methods§
Sourcefn fetch(&self, key: &str) -> ProviderResult<Vec<u8>>
fn fetch(&self, key: &str) -> ProviderResult<Vec<u8>>
Fetches the raw bytes for key, or returns an error.
Implementations should be cheap to call — the renderer may fetch the same key multiple times in a single request and expects in-process memoisation upstream.
§Errors
ProviderError::NotFoundifkeyis not present.ProviderError::Backendfor any other failure.
§Examples
use ssg_core::{ContentProvider, MemoryContentProvider};
let mut mem = MemoryContentProvider::new();
mem.insert("page.md", b"# Hello".to_vec());
let bytes = mem.fetch("page.md").unwrap();
assert_eq!(bytes, b"# Hello");Provided Methods§
Sourcefn fetch_string(&self, key: &str) -> ProviderResult<String>
fn fetch_string(&self, key: &str) -> ProviderResult<String>
Convenience: fetches key and decodes as UTF-8.
Default impl wraps Self::fetch + String::from_utf8.
Adapters that store text natively (KV strings, Edge Config
JSON values) can override for a zero-copy path.
§Errors
- Any error returned by
Self::fetch. ProviderError::Backendif the bytes are not valid UTF-8.
§Examples
use ssg_core::{ContentProvider, MemoryContentProvider};
let mut mem = MemoryContentProvider::new();
mem.insert("a.md", b"hello".to_vec());
assert_eq!(mem.fetch_string("a.md").unwrap(), "hello");Sourcefn contains(&self, key: &str) -> bool
fn contains(&self, key: &str) -> bool
Reports whether key exists without materialising the bytes.
Default impl delegates to Self::fetch and discards the
payload. Adapters with a cheaper HEAD-style probe (CDN cache,
KV metadata) SHOULD override.
§Examples
use ssg_core::{ContentProvider, MemoryContentProvider};
let mut mem = MemoryContentProvider::new();
mem.insert("k", b"v".to_vec());
assert!(mem.contains("k"));
assert!(!mem.contains("missing"));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".