You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
lee a1894a8160 adding "mut" and removing extra exercise 3 years ago
..
README.md adding "mut" and removing extra exercise 3 years ago

README.md

string literal

Instructions

Create the following functions:

  • is_empty, that returns true if a string is empty
  • is_ascii, that returns true if all characters of a given string is in ASCII range
  • contains, that returns true if the string contains a pattern given
  • split_at, that divides a string in two returning a tuple
  • `find', that returns the index if the first character of a given string that matches the pattern

This exercise will test the heap allocation of your function! So try your best to allocate the minimum data on the heap! (hit: &str)

Notions

Expected Functions

fn is_empty(v: &str) -> bool {
}

fn is_ascii(v: &str) -> bool {
}

fn contains(v: &str, pat: &str) -> bool {
}

fn split_at(v: &str, index: usize) -> (&str, &str) {
}

fn find(v: &str, pat: char) -> usize {
}

Usage

Here is a program to test your function

use string_literal::*;

fn main() {
    println!("{}", is_empty(""));
    println!("{}", is_ascii("rust"));
    println!("{}", contains("rust", "ru"));
    println!("{:?}", split_at("rust", 2));
    println!("{}", find("rust", 'u'));
}

And its output

student@ubuntu:~/[[ROOT]]/test$ cargo run
true
true
true
("ru", "st")
1
student@ubuntu:~/[[ROOT]]/test$