Code shared from the Rust Playground
#![allow(unused)] | |
fn main() { | |
use std::path::{Path, PathBuf}; | |
let path = Path::new("/test/haha/foo.txt/"); | |
assert_eq!(path.strip_prefix("/"), Ok(Path::new("test/haha/foo.txt"))); | |
assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt"))); | |
assert_eq!(path.strip_prefix("/test/"), Ok(Path::new("haha/foo.txt"))); | |
assert_eq!(path.strip_prefix("/test/haha/foo.txt"), Ok(Path::new(""))); | |
assert_eq!(path.strip_prefix("/test/haha/foo.txt/"), Ok(Path::new(""))); | |
assert_eq!(path.strip_prefix("test").is_ok(), false); | |
assert_eq!(path.strip_prefix("/haha").is_ok(), false); | |
let prefix = PathBuf::from("/test/"); | |
assert_eq!(path.strip_prefix(prefix), Ok(Path::new("haha/foo.txt"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment