apply clippy suggestions

This commit is contained in:
Adrian Wannenmacher 2022-12-13 16:19:40 +01:00
parent 83f6984b0a
commit 4677a00adc
No known key found for this signature in database
GPG key ID: 19D986ECB1E492D5
13 changed files with 18 additions and 22 deletions

View file

@ -189,7 +189,7 @@ impl<T: Clone> Segment<T> {
pub fn gen_sitemap(&self) -> Vec<String> { pub fn gen_sitemap(&self) -> Vec<String> {
let mut res = Vec::new(); let mut res = Vec::new();
res.push(String::from("/")); res.push(String::from("/"));
gen_sitemap(&self, "", &mut res); gen_sitemap(self, "", &mut res);
res res
} }
@ -213,7 +213,7 @@ impl<T: Clone> Segment<T> {
pub fn gen_parameter_sitemap(&self, parameters: &BTreeMap<Name, Vec<String>>) -> Vec<String> { pub fn gen_parameter_sitemap(&self, parameters: &BTreeMap<Name, Vec<String>>) -> Vec<String> {
let mut res = Vec::new(); let mut res = Vec::new();
res.push(String::from("/")); res.push(String::from("/"));
gen_parameter_sitemap(&self, parameters, "", &mut res); gen_parameter_sitemap(self, parameters, "", &mut res);
res res
} }
} }

View file

@ -146,7 +146,7 @@ where
( (
Self { Self {
history, history,
names: names, names,
routes, routes,
receiver, receiver,
state: Arc::clone(&state), state: Arc::clone(&state),
@ -444,7 +444,7 @@ where
false false
} else { } else {
(self.subscriber_update)(id.as_ref().clone()); (self.subscriber_update)(id.as_ref().clone());
previous.push(id.clone()); previous.push(id);
true true
} }
} else { } else {

View file

@ -65,7 +65,7 @@ impl<T: Clone> RouterState<T> {
/// Get the `href` for the `target`. /// Get the `href` for the `target`.
pub fn href(&self, target: &NavigationTarget) -> String { 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 { Either::Left(Either::Left(i)) => match &self.prefix {
Some(p) => format!("{p}{i}"), Some(p) => format!("{p}{i}"),
None => i, None => i,

View file

@ -13,10 +13,10 @@ pub fn resolve_name(
parameters: &HashMap<Name, String>, parameters: &HashMap<Name, String>,
) -> Option<String> { ) -> Option<String> {
debug_assert!( debug_assert!(
map.contains_key(&name), map.contains_key(name),
"named navigation to unknown name: {name}" "named navigation to unknown name: {name}"
); );
let target = map.get(&name)?; let target = map.get(name)?;
let mut res = String::new(); let mut res = String::new();
for t in target { for t in target {

View file

@ -27,7 +27,7 @@ pub fn resolve_target(
if !s.starts_with('?') { if !s.starts_with('?') {
p += "?"; p += "?";
} }
p += &s; p += s;
} }
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
Query::List(l) => { Query::List(l) => {
@ -44,8 +44,8 @@ pub fn resolve_target(
p p
}) })
.map(|p| Either::Left(p)) .map(Either::Left)
.unwrap_or(Either::Right(name.clone())), .unwrap_or_else(|| Either::Right(name.clone())),
), ),
NavigationTarget::External(e) => Either::Right(e.to_string()), NavigationTarget::External(e) => Either::Right(e.to_string()),
} }

View file

@ -4,7 +4,7 @@ use dioxus_router_core::prelude::{named, FailureExternalNavigation as FENName, R
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn FailureExternalNavigation(cx: Scope) -> Element { 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, \ "`FailureExternalNavigation` can only be mounted by the router itself, \
since it is not exposed", since it is not exposed",
); );

View file

@ -56,7 +56,7 @@ pub fn GoBackButton<'a>(cx: Scope<'a, HistoryButtonProps<'a>>) -> Element {
let HistoryButtonProps { children } = cx.props; let HistoryButtonProps { children } = cx.props;
// hook up to router // hook up to router
let router = match use_router_internal(&cx) { let router = match use_router_internal(cx) {
Some(r) => r, Some(r) => r,
#[allow(unreachable_code)] #[allow(unreachable_code)]
None => { None => {
@ -131,7 +131,7 @@ pub fn GoForwardButton<'a>(cx: Scope<'a, HistoryButtonProps<'a>>) -> Element {
let HistoryButtonProps { children } = cx.props; let HistoryButtonProps { children } = cx.props;
// hook up to router // hook up to router
let router = match use_router_internal(&cx) { let router = match use_router_internal(cx) {
Some(r) => r, Some(r) => r,
#[allow(unreachable_code)] #[allow(unreachable_code)]
None => { None => {

View file

@ -114,7 +114,7 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
} = cx.props; } = cx.props;
// hook up to router // hook up to router
let router = match use_router_internal(&cx) { let router = match use_router_internal(cx) {
Some(r) => r, Some(r) => r,
#[allow(unreachable_code)] #[allow(unreachable_code)]
None => { None => {

View file

@ -69,7 +69,7 @@ pub fn Outlet(cx: Scope<OutletProps>) -> Element {
let OutletProps { depth, name } = cx.props; let OutletProps { depth, name } = cx.props;
// hook up to router // hook up to router
let router = match use_router_internal(&cx) { let router = match use_router_internal(cx) {
Some(r) => r, Some(r) => r,
#[allow(unreachable_code)] #[allow(unreachable_code)]
None => { None => {

View file

@ -58,7 +58,6 @@ use crate::{RouterError, utils::use_router_internal::use_router_internal};
/// # let _ = vdom.rebuild(); /// # let _ = vdom.rebuild();
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><p>Content</p>"); /// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><p>Content</p>");
/// ``` /// ```
#[must_use]
pub fn use_navigate(cx: &ScopeState) -> Result<Navigator<ScopeId>, RouterError> { pub fn use_navigate(cx: &ScopeState) -> Result<Navigator<ScopeId>, RouterError> {
match use_router_internal(cx) { match use_router_internal(cx) {
Some(r) => Ok(r.sender.clone().into()), Some(r) => Ok(r.sender.clone().into()),

View file

@ -56,10 +56,7 @@ use crate::{utils::use_router_internal::use_router_internal, RouterError};
/// ``` /// ```
/// ///
/// [`use_router`]: crate::hooks::use_router /// [`use_router`]: crate::hooks::use_router
#[must_use] pub fn use_route(cx: &ScopeState) -> Result<RwLockReadGuard<RouterState<Component>>, RouterError> {
pub fn use_route<'a>(
cx: &'a ScopeState,
) -> Result<RwLockReadGuard<'a, RouterState<Component>>, RouterError> {
match use_router_internal(cx) { match use_router_internal(cx) {
Some(r) => loop { Some(r) => loop {
if let Some(s) = r.state.try_read() { if let Some(s) = r.state.try_read() {

View file

@ -192,7 +192,7 @@ impl Default for RouterConfiguration {
failure_external_navigation: comp(FailureExternalNavigation), failure_external_navigation: comp(FailureExternalNavigation),
failure_named_navigation: comp(FailureNamedNavigation), failure_named_navigation: comp(FailureNamedNavigation),
failure_redirection_limit: comp(FailureRedirectionLimit), failure_redirection_limit: comp(FailureRedirectionLimit),
history: Box::new(MemoryHistory::default()), history: Box::<MemoryHistory>::default(),
on_update: None, on_update: None,
synchronous: false, synchronous: false,
} }

View file

@ -15,7 +15,7 @@ use crate::contexts::router::RouterContext;
/// - Otherwise [`Some`]. /// - Otherwise [`Some`].
/// ///
/// [`use_router`]: crate::hooks::use_router /// [`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())); let id = cx.use_hook(|| Arc::new(cx.scope_id()));
cx.use_hook(|| { cx.use_hook(|| {