Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created September 17, 2025 14:07
Show Gist options
  • Select an option

  • Save mizchi/00858a6127b5c81c347dff513b00344d to your computer and use it in GitHub Desktop.

Select an option

Save mizchi/00858a6127b5c81c347dff513b00344d to your computer and use it in GitHub Desktop.
///|
test "String to Bytes conversion" {
fn find_index(url : Bytes) -> Int? {
url.find("://")
}
let url = "https://www.example.ocom"
let url_bytes : Bytes = "https://example.com"
inspect(url.find("://"), content="Some(5)")
inspect(find_index("https://example.com"), content="Some(5)")
inspect(find_index(b"https://example.com"), content="Some(5)")
inspect(find_index(url_bytes), content="Some(5)")
inspect(find_index("https://example.com"), content="Some(5)")
inspect(find_index(@encoding/utf8.encode(url)), content="Some(5)")
// Can't compile
// inspect(find_index(url), content="Some(5)")
// Error: b'' and to_bytes() are different
inspect(find_index(url.to_bytes()), content="Some(5)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment