Skip to content

I built this crate to practice lifetimes, a concept most beginner Rust programmers find difficult to grasp. I followed a tutorial by Jon Gjengset. What we are implementing is already in the standard library, but what’s a better way to learn lifetimes than by building something with them?

Notifications You must be signed in to change notification settings

amschel99/strsplit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Strsplit

Rust Crates.io Docs.rs

strsplit is a crate that provides a Strsplit struct and a utility function until_char for splitting strings efficiently.

Usage

Add this to your Cargo.toml:

[dependencies]
strsplit = "0.1.1"

Then you can use it in your code:

use strsplit::Strsplit;

let haystack = "a,b,c,d,e,f";
let letters: Vec<_> = Strsplit::new(&haystack, ",").collect();
assert_eq!(letters, vec!["a", "b", "c", "d", "e", "f"]);

Function: until_char

The until_char function returns the string before the first instance of the delimiter is found.

use strsplit::until_char;
let haystack = "hello";
let trimmed = until_char(&haystack, 'o');
assert_eq!(trimmed, "hell");

About

I built this crate to practice lifetimes, a concept most beginner Rust programmers find difficult to grasp. I followed a tutorial by Jon Gjengset. What we are implementing is already in the standard library, but what’s a better way to learn lifetimes than by building something with them?

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages