pub struct FeedGenerator { /* private fields */ }Expand description
Implementations§
Source§impl FeedGenerator
impl FeedGenerator
Sourcepub fn new(did: impl Into<String>) -> Self
pub fn new(did: impl Into<String>) -> Self
Create a new feed generator with the given service DID.
The DID identifies this feed generator on the AT Protocol network
(e.g. "did:web:feeds.example.com").
Sourcepub fn feed<F, Fut>(
self,
id: &str,
display_name: &str,
description: Option<&str>,
handler: F,
) -> Selfwhere
F: Fn(FeedRequest, AppState) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<FeedSkeleton, XrpcError>> + Send + 'static,
pub fn feed<F, Fut>(
self,
id: &str,
display_name: &str,
description: Option<&str>,
handler: F,
) -> Selfwhere
F: Fn(FeedRequest, AppState) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<FeedSkeleton, XrpcError>> + Send + 'static,
Register a feed with the given ID, display name, optional description, and handler function.
The handler is called each time a client requests the feed skeleton.
It receives a FeedRequest and the AppState, and must return
a FeedSkeleton or an XrpcError.
§Example
ⓘ
async fn chronological(
req: FeedRequest,
state: AppState,
) -> Result<FeedSkeleton, XrpcError> {
// query DB, build skeleton ...
Ok(FeedSkeleton { feed: vec![], cursor: None })
}
let gen = FeedGenerator::new("did:web:example.com")
.feed("chrono", "Chronological", Some("Latest posts"), chronological);Sourcepub fn feed_with_config<F, Fut>(self, config: FeedConfig, handler: F) -> Selfwhere
F: Fn(FeedRequest, AppState) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<FeedSkeleton, XrpcError>> + Send + 'static,
pub fn feed_with_config<F, Fut>(self, config: FeedConfig, handler: F) -> Selfwhere
F: Fn(FeedRequest, AppState) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<FeedSkeleton, XrpcError>> + Send + 'static,
Register a feed from an existing FeedConfig and handler function.
This is useful when feed configurations are loaded from atrg.toml
or another config source.
Sourcepub fn feed_count(&self) -> usize
pub fn feed_count(&self) -> usize
Return the number of registered feeds.
Sourcepub fn into_router(self) -> Router<AppState>
pub fn into_router(self) -> Router<AppState>
Build an Axum router with the XRPC feed endpoints.
Registers:
GET /xrpc/app.bsky.feed.describeFeedGeneratorGET /xrpc/app.bsky.feed.getFeedSkeleton
Auto Trait Implementations§
impl Freeze for FeedGenerator
impl !RefUnwindSafe for FeedGenerator
impl Send for FeedGenerator
impl Sync for FeedGenerator
impl Unpin for FeedGenerator
impl UnsafeUnpin for FeedGenerator
impl !UnwindSafe for FeedGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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