Comments (5)
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.
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.
OK, maybe it's more tricky than I thought. This is just because I use Path
s 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.
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.
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)
- AlpmList and Lifetimes HOT 6
- Non-optional `Package::arch` ? HOT 5
- filename method of Package should return Option<&str> HOT 5
- Tracking for functions that should return Option
- Possible UB in AnyQuestion::question HOT 2
- API changes for v3 HOT 8
- Add a CHANGELOG / git tag for published versions HOT 2
- Lifetime on callbacks HOT 2
- Build fails HOT 2
- `Alpm` handles and Concurrency HOT 5
- Segfault when dropping Alpm after calling Db::groups() HOT 2
- error[E0308]: mismatched types HOT 6
- APIs for file checksums? HOT 3
- Static feature flag doesn't actually work HOT 4
- alpm & alpm-sys rebuilds every time if the static feature is enabled HOT 4
- alpm.rs 3.0.4 fails to build with pacman 6.1.0 HOT 2
- Missing `Send` impl for `Alpm`? HOT 4
- Compilation error on aarch64 HOT 3
- Should CommitData::FileConflict carry OwnedFileConflict instead of OwnedConflict? HOT 1
- Alpm does not implement Send HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alpm.rs.