Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Newtype so that Rust-url can be IntoRoutable #1579

Merged
merged 3 commits into from Oct 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/router/src/components/link.rs
Expand Up @@ -11,6 +11,8 @@ use crate::navigation::NavigationTarget;
use crate::prelude::Routable;
use crate::utils::use_router_internal::use_router_internal;

use url::Url as RustUrl;

/// Something that can be converted into a [`NavigationTarget`].
#[derive(Clone)]
pub enum IntoRoutable {
Expand Down Expand Up @@ -53,6 +55,21 @@ impl From<&str> for IntoRoutable {
}
}

/// Newtype to make is easier to work with rust-url type that other crates commonly use.
pub struct Url(RustUrl);
ealmloff marked this conversation as resolved.
Show resolved Hide resolved

impl From<Url> for IntoRoutable {
fn from(url: Url) -> Self {
IntoRoutable::FromStr(url.0.to_string())
}
}

impl From<&Url> for IntoRoutable {
fn from(url: &Url) -> Self {
IntoRoutable::FromStr(url.0.to_string())
}
}

/// The properties for a [`Link`].
#[derive(Props)]
pub struct LinkProps<'a> {
Expand Down