pub struct LinkHeader { /* private fields */ }Expand description
Builder for constructing RFC 8288 Link headers.
Supports multiple links in a single header value, pagination helpers, and custom relation types.
§Example
use fastapi_core::{LinkHeader, LinkRel};
let header = LinkHeader::new()
.link("https://api.example.com/users?page=2", LinkRel::Next)
.link("https://api.example.com/users?page=1", LinkRel::Prev)
.link("https://api.example.com/users?page=1", LinkRel::First)
.link("https://api.example.com/users?page=5", LinkRel::Last);
assert!(header.to_string().contains("rel=\"next\""));Implementations§
Source§impl LinkHeader
impl LinkHeader
Sourcepub fn link(self, url: impl Into<String>, rel: LinkRel) -> Self
pub fn link(self, url: impl Into<String>, rel: LinkRel) -> Self
Add a link with the given URL and relation.
Sourcepub fn paginate(
self,
base_url: &str,
page: u64,
per_page: u64,
total: u64,
) -> Self
pub fn paginate( self, base_url: &str, page: u64, per_page: u64, total: u64, ) -> Self
Add pagination links from page/per_page/total parameters.
Generates first, last, next, prev, and self links
using the given base URL and query parameters.
Sourcepub fn to_header_value(&self) -> String
pub fn to_header_value(&self) -> String
Convert to the header value string (RFC 8288 format).
Trait Implementations§
Source§impl Clone for LinkHeader
impl Clone for LinkHeader
Source§fn clone(&self) -> LinkHeader
fn clone(&self) -> LinkHeader
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LinkHeader
impl Debug for LinkHeader
Source§impl Default for LinkHeader
impl Default for LinkHeader
Source§fn default() -> LinkHeader
fn default() -> LinkHeader
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for LinkHeader
impl RefUnwindSafe for LinkHeader
impl Send for LinkHeader
impl Sync for LinkHeader
impl Unpin for LinkHeader
impl UnwindSafe for LinkHeader
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).