Here’s a function that takes a string slice as an input and returns a string slice that contains the first word of the input string.

The function uses byte manipulation to search for the first space character in the input string, which indicates the end of the first word.
If no space character is found, the function returns a string slice containing the entire input string.

Scroll to Top