Code Monkey home page Code Monkey logo

Comments (5)

Morganamilo avatar Morganamilo commented on August 27, 2024

To turn a string into a cstring. You need to append a null byte to the end. If you pass in a String then you can take ownership of it and just append the byte.

If the function took in a str, then you'd have still have to allocate a buffer so you can append a byte to it.

This is why I went for String.

The actual cstring API takes in a Into<Vec<u8>> though and not into<String>. I made that change to make the docs look more normal. And I don't see many people wanting to pass in byte arrays.

For the second point, do you mean things like, description and URL? In that case, I'm not really sure what to do. I tried to make this API stick as closely to alpm as possible. And in alpm, if desc is empty, the function alpm_pkg_get_desc() actually returns an empty string, not a null pointer.

But I don't think I'm really against changing it, as long as it's consistent and doesn't make the API too annoying to use with options everywhere.

from alpm.rs.

Morganamilo avatar Morganamilo commented on August 27, 2024

For Path specifically, it's even worse. As Path is backed by OsString, the actual data stored is OS dependant, and the alpm functions expect a regular char*, so if we did take in a Path, we'd have to convert it back to the format alpm expects.

from alpm.rs.

0x1793d1 avatar 0x1793d1 commented on August 27, 2024

OK, maybe it's more tricky than I thought. This is just because I use Paths when manipulating files.

I will probably use path.as_ref().to_owned().display().to_string() to convert my path.

For the second point, I think it's always easier with options given that you can do unwrap_or andok_or to manage the result.

E.g., I want to return an error when the architecture field is missing. In this situation I could do:

let arch = pkg.arch().ok_or(MyErrorType::MissingField)?;

Or if I want the same behaviour as now:

let arch = pkg.arch().unwrap_or("");

from alpm.rs.

Morganamilo avatar Morganamilo commented on August 27, 2024

I'm fine with making arch, desc, etc Options.

With the path stuff. The reason you howe to call . display() and can't just convert it to a string is that a path may contain not unicode so the conversion is lossy.

Thin is fine for displaying. But if you actually want to use the file then it may end up opening a different fine. Even if the chances are very low.

from alpm.rs.

0x1793d1 avatar 0x1793d1 commented on August 27, 2024

OK! I'll do the modification ASAP.
Regarding the path stuff: another way to do is to use path.to_str().
sdl2_image use this, sqlite too.

from alpm.rs.

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.