Created
July 22, 2019 06:09
-
-
Save rust-play/6ea16971a7335e551e65168652b4990d to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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