Code Monkey home page Code Monkey logo

Comments (3)

mgeisler avatar mgeisler commented on June 15, 2024

I just looked at this and I now remember why fill_inplace takes a &mut String instead of &mut str: I cannot find a suitable into_bytes method for &str.

There is a as_bytes_mut method, but it is unsafe. Have I missed some other option to convert a &str into [u8] in-place?

from textwrap.

Kestrer avatar Kestrer commented on June 15, 2024

I don't think there's a way to do this using just the standard library without unsafe. I created the with-str-bytes crate to allow this to be performed safely, if you don't mind another dependency (it's tiny - the entire crate including tests is just 132 lines).

from textwrap.

mgeisler avatar mgeisler commented on June 15, 2024

Hey @Kestrer, okay, good to hear that I probably didn't miss anything here. Sorry for the late responses, recently I've found little time for open source work.

I'll pass on adding a new dependency for this — while it would be pretty if the signature was &mut str, I don't think it's a huge problem that the function demands a String.

from textwrap.

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.