pub trait LocalePage: Sized {
// Required method
fn alternates<L: Locale>(
self,
origin: Origin,
url: impl Fn(L) -> Url,
) -> Self;
}Expand description
Adds the alternate of each locale to a Page.
Required Methods§
Sourcefn alternates<L: Locale>(self, origin: Origin, url: impl Fn(L) -> Url) -> Self
fn alternates<L: Locale>(self, origin: Origin, url: impl Fn(L) -> Url) -> Self
Names the page’s address in each locale of L, where url gives the address in one.
It adds one Page::alternate per locale of Locale::ALL, tagged
with Locale::tag, and a Page::alternate_default at the first
locale, the default that negotiate falls back to.
hypersig::routes! {
fn pages(Router<()>);
const POST: Route<(Lang, u32)> = "/{lang}/posts/{id}" => post;
}
const SITE: Origin = Origin::new("https://example.com");
let html = Page::new("Post", Post {})
.alternates(SITE, |lang: Lang| POST.url((lang, 3)))
.render();
assert!(html.contains(r#"<link rel="alternate" hreflang="en" href="https://example.com/en/posts/3">"#));
assert!(html.contains(r#"<link rel="alternate" hreflang="ja" href="https://example.com/ja/posts/3">"#));
assert!(html.contains(r#"<link rel="alternate" hreflang="x-default" href="https://example.com/en/posts/3">"#));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".