Open
Description
In vector-master/lib/docs-renderer/src/renderer.rs, these 2 comments indicate that code will panic if path == "/", but actually code will not.
/// # Panics
///
/// If the path does not start with a forward slash, this method will panic. Likewise, if the
/// path is _only_ a forward slash (aka there is no segment to describe the key within the
/// object to write the value to), this method will panic.
pub fn write<V: Into<Value>>(&mut self, path: &str, value: V) {
if !path.starts_with('/') {
panic!("Paths must always start with a leading forward slash (`/`).");
}
...
}
/// # Panics
///
/// If the path does not start with a forward slash, this method will panic. Likewise, if the
/// path is _only_ a forward slash (aka there is no segment to describe the key within the
/// object to write the value to), this method will panic.
///
/// If any nested object within the path does not yet exist, it will be created. If any segment,
/// other than the leaf segment, points to a value that is not an object/map, this method will
/// panic.
pub fn delete(&mut self, path: &str) -> bool {
if !path.starts_with('/') {
panic!("Paths must always start with a leading forward slash (`/`).");
}
...
}
Following 2 tests are all passed.
#[cfg(test)]
mod tests{
use crate::renderer::RenderData;
#[test]
fn test_1(){
RenderData::default().write("/", "hello");
}
#[test]
fn test_2(){
RenderData::default().delete("/");
}
}