forked from root/public
Augusto
3 years ago
4 changed files with 86 additions and 0 deletions
@ -0,0 +1,12 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
[[package]] |
||||
name = "delete_prefix" |
||||
version = "0.1.0" |
||||
|
||||
[[package]] |
||||
name = "delete_prefix_test" |
||||
version = "0.1.0" |
||||
dependencies = [ |
||||
"delete_prefix", |
||||
] |
@ -0,0 +1,10 @@
|
||||
[package] |
||||
name = "delete_prefix_test" |
||||
version = "0.1.0" |
||||
authors = ["Augusto <aug.ornelas@gmail.com>"] |
||||
edition = "2018" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
delete_prefix = { path = "../../../../rust-piscine-solutions/delete_prefix"} |
@ -0,0 +1,32 @@
|
||||
// Define the function `delete_prefix(prefix: &str, s: &str) -> Option<&str>`
|
||||
// That takes 2 slices of string and returns the string of slice s
|
||||
// with the `prefix` removed wrapped in Some
|
||||
// If `prefix ` is not contained in `s` return None
|
||||
|
||||
// Example:
|
||||
// delete_prefix("hello, ", "hello, world")? == "world"
|
||||
// delete_prefix("not", "win");
|
||||
|
||||
use delete_prefix::*; |
||||
|
||||
#[allow(dead_code)] |
||||
fn main() { |
||||
println!("{:?}", delete_prefix("ab", "abcdefghijklmnop")); |
||||
println!("{:?}", delete_prefix("x", "abcdefghijklmnop")); |
||||
} |
||||
|
||||
#[cfg(test)] |
||||
mod tests { |
||||
use super::*; |
||||
|
||||
#[test] |
||||
fn test_delete_prefix() { |
||||
assert_eq!(delete_prefix("john", "john wick"), Some(" wick")); |
||||
|
||||
assert_eq!(delete_prefix("ab", "b"), None); |
||||
|
||||
assert_eq!(delete_prefix("aa", "ab"), None); |
||||
|
||||
assert_eq!(delete_prefix("á©", "á©ab"), Some("ab")); |
||||
} |
||||
} |
@ -0,0 +1,32 @@
|
||||
## delete_prefix |
||||
|
||||
### Instructions |
||||
|
||||
Define the function `delete_prefix(prefix, s)` that returns the string slice `s` with the `prefix` removed wrapped in Some. If `prefix ` is not contained in `s` return None |
||||
|
||||
### Expected Function |
||||
|
||||
```rust |
||||
fn delete_prefix(prefix: &str, s: &str) -> Option<&str> { |
||||
} |
||||
``` |
||||
|
||||
### Usage |
||||
|
||||
Here is a program to test your function. |
||||
|
||||
```rust |
||||
fn main() { |
||||
println!("{:?}", delete_prefix("ab", "abcdefghijklmnop")); |
||||
println!("{:?}", delete_prefix("x", "abcdefghijklmnop")); |
||||
} |
||||
``` |
||||
|
||||
And its output |
||||
|
||||
```console |
||||
student@ubuntu:~/[[ROOT]]/test$ cargo run |
||||
Some("cdefghijklmnop") |
||||
None |
||||
student@ubuntu:~/[[ROOT]]/test$ |
||||
``` |
Loading…
Reference in new issue