You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am thinking about adding another trait to represent string, the definition will be same as our NixPath trait, and these 2 traits only differ in semantics, NixPath is for path, this new trait is for string.
By adding this trait, we split "C string" (C does not have a string type, it is only a sequence of chars followed by a NUL) into 2 categories by semantics:
path
string
Currently, it will be used in 2 interfaces if added:
The ident argument of openlog() on non-Linux systems
It is the name of the program that the spawned child process will execute
This argument should not be called path, I will rename it to file
Alternative approaches
Just use the NixPath trait
It will definitely work, though it will feel weird semantically due to the Path in its name. Or maybe we can rename the trait to something like NixCString?
Use S: AsRef<OsStr>
openlog() currently uses this approach, after converting it to &OsStr we can use NixPath under the hood, so it is convenient:
<OsStrasNixPath>::with_nix_path(os_str.as_ref(), |c_str| {// do something with c_str});
The only flaw of this method IMHO is that users cannot use &CStr because CStr is not AsRef<OsStr>, but &CStr should be allowed.
The text was updated successfully, but these errors were encountered:
I am thinking about adding another trait to represent string, the definition will be same as our
NixPath
trait, and these 2 traits only differ in semantics,NixPath
is for path, this new trait is for string.By adding this trait, we split "C string" (C does not have a string type, it is only a sequence of chars followed by a NUL) into 2 categories by semantics:
Currently, it will be used in 2 interfaces if added:
The
ident
argument ofopenlog()
on non-Linux systemsnix/src/syslog.rs
Lines 45 to 47 in 0c40b8d
From man page:
The
path
argument ofposix_spawnp()
nix/src/spawn.rs
Lines 396 to 397 in 0c40b8d
It is the name of the program that the spawned child process will execute
Alternative approaches
Just use the
NixPath
traitIt will definitely work, though it will feel weird semantically due to the
Path
in its name. Or maybe we can rename the trait to something likeNixCString
?Use
S: AsRef<OsStr>
openlog()
currently uses this approach, after converting it to&OsStr
we can useNixPath
under the hood, so it is convenient:The only flaw of this method IMHO is that users cannot use
&CStr
becauseCStr
is notAsRef<OsStr>
, but&CStr
should be allowed.The text was updated successfully, but these errors were encountered: