mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 20:53:06 +00:00
apply clippy suggestions
This commit is contained in:
parent
83f6984b0a
commit
4677a00adc
13 changed files with 18 additions and 22 deletions
|
@ -189,7 +189,7 @@ impl<T: Clone> Segment<T> {
|
|||
pub fn gen_sitemap(&self) -> Vec<String> {
|
||||
let mut res = Vec::new();
|
||||
res.push(String::from("/"));
|
||||
gen_sitemap(&self, "", &mut res);
|
||||
gen_sitemap(self, "", &mut res);
|
||||
res
|
||||
}
|
||||
|
||||
|
@ -213,7 +213,7 @@ impl<T: Clone> Segment<T> {
|
|||
pub fn gen_parameter_sitemap(&self, parameters: &BTreeMap<Name, Vec<String>>) -> Vec<String> {
|
||||
let mut res = Vec::new();
|
||||
res.push(String::from("/"));
|
||||
gen_parameter_sitemap(&self, parameters, "", &mut res);
|
||||
gen_parameter_sitemap(self, parameters, "", &mut res);
|
||||
res
|
||||
}
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ where
|
|||
(
|
||||
Self {
|
||||
history,
|
||||
names: names,
|
||||
names,
|
||||
routes,
|
||||
receiver,
|
||||
state: Arc::clone(&state),
|
||||
|
@ -444,7 +444,7 @@ where
|
|||
false
|
||||
} else {
|
||||
(self.subscriber_update)(id.as_ref().clone());
|
||||
previous.push(id.clone());
|
||||
previous.push(id);
|
||||
true
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<T: Clone> RouterState<T> {
|
|||
|
||||
/// Get the `href` for the `target`.
|
||||
pub fn href(&self, target: &NavigationTarget) -> String {
|
||||
match resolve_target(&self.name_map, &target) {
|
||||
match resolve_target(&self.name_map, target) {
|
||||
Either::Left(Either::Left(i)) => match &self.prefix {
|
||||
Some(p) => format!("{p}{i}"),
|
||||
None => i,
|
||||
|
|
|
@ -13,10 +13,10 @@ pub fn resolve_name(
|
|||
parameters: &HashMap<Name, String>,
|
||||
) -> Option<String> {
|
||||
debug_assert!(
|
||||
map.contains_key(&name),
|
||||
map.contains_key(name),
|
||||
"named navigation to unknown name: {name}"
|
||||
);
|
||||
let target = map.get(&name)?;
|
||||
let target = map.get(name)?;
|
||||
|
||||
let mut res = String::new();
|
||||
for t in target {
|
||||
|
|
|
@ -27,7 +27,7 @@ pub fn resolve_target(
|
|||
if !s.starts_with('?') {
|
||||
p += "?";
|
||||
}
|
||||
p += &s;
|
||||
p += s;
|
||||
}
|
||||
#[cfg(feature = "serde")]
|
||||
Query::List(l) => {
|
||||
|
@ -44,8 +44,8 @@ pub fn resolve_target(
|
|||
|
||||
p
|
||||
})
|
||||
.map(|p| Either::Left(p))
|
||||
.unwrap_or(Either::Right(name.clone())),
|
||||
.map(Either::Left)
|
||||
.unwrap_or_else(|| Either::Right(name.clone())),
|
||||
),
|
||||
NavigationTarget::External(e) => Either::Right(e.to_string()),
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use dioxus_router_core::prelude::{named, FailureExternalNavigation as FENName, R
|
|||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn FailureExternalNavigation(cx: Scope) -> Element {
|
||||
let state = use_route(&cx).expect(
|
||||
let state = use_route(cx).expect(
|
||||
"`FailureExternalNavigation` can only be mounted by the router itself, \
|
||||
since it is not exposed",
|
||||
);
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn GoBackButton<'a>(cx: Scope<'a, HistoryButtonProps<'a>>) -> Element {
|
|||
let HistoryButtonProps { children } = cx.props;
|
||||
|
||||
// hook up to router
|
||||
let router = match use_router_internal(&cx) {
|
||||
let router = match use_router_internal(cx) {
|
||||
Some(r) => r,
|
||||
#[allow(unreachable_code)]
|
||||
None => {
|
||||
|
@ -131,7 +131,7 @@ pub fn GoForwardButton<'a>(cx: Scope<'a, HistoryButtonProps<'a>>) -> Element {
|
|||
let HistoryButtonProps { children } = cx.props;
|
||||
|
||||
// hook up to router
|
||||
let router = match use_router_internal(&cx) {
|
||||
let router = match use_router_internal(cx) {
|
||||
Some(r) => r,
|
||||
#[allow(unreachable_code)]
|
||||
None => {
|
||||
|
|
|
@ -114,7 +114,7 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
|
|||
} = cx.props;
|
||||
|
||||
// hook up to router
|
||||
let router = match use_router_internal(&cx) {
|
||||
let router = match use_router_internal(cx) {
|
||||
Some(r) => r,
|
||||
#[allow(unreachable_code)]
|
||||
None => {
|
||||
|
|
|
@ -69,7 +69,7 @@ pub fn Outlet(cx: Scope<OutletProps>) -> Element {
|
|||
let OutletProps { depth, name } = cx.props;
|
||||
|
||||
// hook up to router
|
||||
let router = match use_router_internal(&cx) {
|
||||
let router = match use_router_internal(cx) {
|
||||
Some(r) => r,
|
||||
#[allow(unreachable_code)]
|
||||
None => {
|
||||
|
|
|
@ -58,7 +58,6 @@ use crate::{RouterError, utils::use_router_internal::use_router_internal};
|
|||
/// # let _ = vdom.rebuild();
|
||||
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><p>Content</p>");
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn use_navigate(cx: &ScopeState) -> Result<Navigator<ScopeId>, RouterError> {
|
||||
match use_router_internal(cx) {
|
||||
Some(r) => Ok(r.sender.clone().into()),
|
||||
|
|
|
@ -56,10 +56,7 @@ use crate::{utils::use_router_internal::use_router_internal, RouterError};
|
|||
/// ```
|
||||
///
|
||||
/// [`use_router`]: crate::hooks::use_router
|
||||
#[must_use]
|
||||
pub fn use_route<'a>(
|
||||
cx: &'a ScopeState,
|
||||
) -> Result<RwLockReadGuard<'a, RouterState<Component>>, RouterError> {
|
||||
pub fn use_route(cx: &ScopeState) -> Result<RwLockReadGuard<RouterState<Component>>, RouterError> {
|
||||
match use_router_internal(cx) {
|
||||
Some(r) => loop {
|
||||
if let Some(s) = r.state.try_read() {
|
||||
|
|
|
@ -192,7 +192,7 @@ impl Default for RouterConfiguration {
|
|||
failure_external_navigation: comp(FailureExternalNavigation),
|
||||
failure_named_navigation: comp(FailureNamedNavigation),
|
||||
failure_redirection_limit: comp(FailureRedirectionLimit),
|
||||
history: Box::new(MemoryHistory::default()),
|
||||
history: Box::<MemoryHistory>::default(),
|
||||
on_update: None,
|
||||
synchronous: false,
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::contexts::router::RouterContext;
|
|||
/// - Otherwise [`Some`].
|
||||
///
|
||||
/// [`use_router`]: crate::hooks::use_router
|
||||
pub(crate) fn use_router_internal<'a>(cx: &'a ScopeState) -> &'a mut Option<RouterContext> {
|
||||
pub(crate) fn use_router_internal(cx: &ScopeState) -> &mut Option<RouterContext> {
|
||||
let id = cx.use_hook(|| Arc::new(cx.scope_id()));
|
||||
|
||||
cx.use_hook(|| {
|
||||
|
|
Loading…
Reference in a new issue