You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-16 14:17:34 +02:00
Improve language around ownership of OsString
(#602)
Based on discussion in #598.
This commit is contained in:
@ -24,11 +24,11 @@ You will convert between all these types:
|
|||||||
- `&str` to `CString`: you need to allocate space for a trailing `\0` character,
|
- `&str` to `CString`: you need to allocate space for a trailing `\0` character,
|
||||||
- `CString` to `*const i8`: you need a pointer to call C functions,
|
- `CString` to `*const i8`: you need a pointer to call C functions,
|
||||||
- `*const i8` to `&CStr`: you need something which can find the trailing `\0` character,
|
- `*const i8` to `&CStr`: you need something which can find the trailing `\0` character,
|
||||||
- `&CStr` to `&[u8]`: you will ultimately return a slice of bytes,
|
- `&CStr` to `&[u8]`: a slice of bytes is the universal interface for "some unknow data",
|
||||||
- `&[u8]` to `&OsStr`: you can create an `OsString` from `&[u8]`. Use
|
- `&[u8]` to `&OsStr`: `&OsStr` is a step towards `OsString`, use
|
||||||
[`OsStrExt`](https://doc.rust-lang.org/std/os/unix/ffi/trait.OsStrExt.html)
|
[`OsStrExt`](https://doc.rust-lang.org/std/os/unix/ffi/trait.OsStrExt.html)
|
||||||
for this.
|
to create it,
|
||||||
- `&OsStr` to `OsString`: you need to take ownership of the data before you call
|
- `&OsStr` to `OsString`: you need to clone the data in `&OsStr` to be able to return it and call
|
||||||
`readdir` again.
|
`readdir` again.
|
||||||
|
|
||||||
The [Nomicon] also has a very useful chapter about FFI.
|
The [Nomicon] also has a very useful chapter about FFI.
|
||||||
|
Reference in New Issue
Block a user