Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Apr 28, 2024
1 parent 8c236ce commit 8e8174f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ impl<T> Router<T> {

/// Remove a given route from the router.
///
/// Returns the value stored under the route if it was found.
///
/// If the route was not found or if the route is incorrect, `None` is returned.
/// Returns the value stored under the route if it was found. If the route was not found or invalid, `None` is returned.
///
/// # Examples
///
Expand All @@ -117,12 +115,12 @@ impl<T> Router<T> {
/// assert_eq!(router.remove("/home/{id}/"), None);
///
/// router.insert("/home/{id}/", "Hello!");
/// // Bad route
/// // unknown route
/// assert_eq!(router.remove("/home/{user}"), None);
/// assert_eq!(router.remove("/home/{id}/"), Some("Hello!"));
///
/// router.insert("/home/{id}/", "Hello!");
/// // Ill-formed route
/// // invalid route
/// assert_eq!(router.remove("/home/{id"), None);
/// assert_eq!(router.remove("/home/{id}/"), Some("Hello!"));
/// ```
Expand Down
16 changes: 8 additions & 8 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ impl<T> Node<T> {
}
}

/// Removes a route from the tree, returning the value if the route existed.
/// The provided path should be the same as the one used to insert the route (including wildcards).
/// removes a route from the tree, returning the value if the route existed.
/// the provided path should be the same as the one used to insert the route (including wildcards).
pub fn remove(&mut self, full_path: impl Into<String>) -> Option<T> {
let mut current = self;
let unescaped = UnescapedRoute::new(full_path.into().into_bytes());
Expand All @@ -198,11 +198,11 @@ impl<T> Node<T> {
node.children.remove(0).value.take()
} else {
let child = node.children.remove(i);
// Indices are only used for static nodes
// indices are only used for static nodes
if child.node_type == NodeType::Static {
node.indices.remove(i);
} else {
// It was a dynamic node, we remove the wildcard child flag
// it was a dynamic node, we remove the wildcard child flag
node.wild_child = false;
}
child.value
Expand All @@ -214,7 +214,7 @@ impl<T> Node<T> {
val.map(UnsafeCell::into_inner)
};

// Specific case if we are removing the root node
// specific case if we are removing the root node
if path == current.prefix.inner() {
let val = current.value.take().map(UnsafeCell::into_inner);
// if the root node has no children, we can just reset it
Expand All @@ -233,7 +233,7 @@ impl<T> Node<T> {
let first = rest[0];
path = rest;

// If there is only one child we can continue with the child node
// if there is only one child we can continue with the child node
if current.children.len() == 1 {
if current.children[0].prefix.inner() == rest {
return drop_child(current, 0);
Expand All @@ -243,7 +243,7 @@ impl<T> Node<T> {
}
}

// If there are many we get the index of the child matching the first byte
// if there are many we get the index of the child matching the first byte
if let Some(i) = current.indices.iter().position(|&c| c == first) {
// continue with the child node
if current.children[i].prefix.inner() == rest {
Expand All @@ -254,7 +254,7 @@ impl<T> Node<T> {
}
}

// If this node has a wildcard child and that it matches our standardized path
// if this node has a wildcard child and that it matches our standardized path
// we continue with that
if current.wild_child
&& !current.children.is_empty()
Expand Down

0 comments on commit 8e8174f

Please sign in to comment.