Giter VIP home page Giter VIP logo

Comments (2)

esoterra avatar esoterra commented on August 16, 2024

A good reference to use for a safe string API would be Rust's std::string::String and std::ffi::OsString which allow users to interact with valid UTF-8 strings and platform-specific string representations respectively.

There are a few differences between Rust's string design and what is proposed above.

  • Rust strings have a String::chars method which allows iterating over the char type instead of treating it as a sequence of strings itself.
  • Rust additionally offers a String::char_indices method that allows you to see the byte indices of each character you iterate over
  • Rust does allow users to do some indexing into strings as byte arrays, but doing so risks a panic (example with index) or returns an Option (example with get).

Users have a tendency to assume indexing is a constant time operation which is not the case for character indexing into UTF-8 and I believe is why that ability is only offered through an iterator (e.g. s.chars().nth(...)) in Rust.

from rfcs.

SeanTAllen avatar SeanTAllen commented on August 16, 2024

FYI there's a String RFC that is being worked on so anyone interested in this might want to check that out:

#179

from rfcs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.