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
The documentation here for UCStr::from_ptr_with_nul is a little self-contradictory - "Safety" claims the pointer mustn't be null, but then "Panics" documents safe behavior (panicing) on null, but then the implementation doesn't check for null and may or may hit debug-only asserts inside of std:
let ptr:*const[C] = slice::from_raw_parts(p, len + 1);
&*(ptr as*constUCStr<C>)
}
Additionally, while UCStr::from_ptr_with_nul doesn't scan for nuls, it appears UCString::from_ptr_with_nul does (and will truncate) - and also handles the len=0 ptr=null case without panicing at all:
Should I create a PR for UCStr to try and return &[UChar::NUL] for the length 0 case? (Maybe UCStr can gain a Default impl?)
Should it scan/truncate too (would change the result of str.len())? Perhaps matching function signatures?
The inconsistent "Safety" vs "Panics" documentation crops up in multiple places - should I try and drop this text from all the "Safety" sections where p is already null-checked soundly and documented to be null-checked under "Panics"?
p must be non-null.
The text was updated successfully, but these errors were encountered:
Not surprised some inconsistencies have popped up, there was some significant internal refactoring. A PR to correct these would be welcome.
Should I create a PR for UCStr to try and return &[UChar::NUL] for the length 0 case? (Maybe UCStr can gain a Default impl?) Should it scan/truncate too (would change the result of str.len())? Perhaps matching function signatures?
In general, _unchecked methods should not scan/truncate, and methods that are passed a len parameter should scan and error on missing/unexpected nuls depending on signature. Methods that receive only the pointer should scan and truncate without error. This should be true for both UCStr and UCString. Getting the zero length behavior consistent would be useful
- Renamed, added, and removed a number of types and functions to increase consistency and clarity.
This also meant using "null" instead of "nul", renaming errors to more clearly convey error,
and trying to be more consistent with name conventions and functionality across types. Check
renamed function docs for any changes in functionality, as there have been some minor tweaks
(mostly relaxing/removing error conditions and reducing panics). Old names have been deprecated
to ease transition. Fixes [#18].
- Improved implementations in some areas to reduce unncessary double allocations.
- Improved documentation and used intra-doc links.
The documentation here for
UCStr::from_ptr_with_nul
is a little self-contradictory - "Safety" claims the pointer mustn't be null, but then "Panics" documents safe behavior (panicing) on null, but then the implementation doesn't check for null and may or may hit debug-only asserts inside ofstd
:widestring-rs/src/ucstr.rs
Line 132 in e7236b6
widestring-rs/src/ucstr.rs
Line 139 in e7236b6
widestring-rs/src/ucstr.rs
Lines 148 to 152 in e7236b6
Additionally, while
UCStr::from_ptr_with_nul
doesn't scan for nuls, it appearsUCString::from_ptr_with_nul
does (and will truncate) - and also handles the len=0 ptr=null case without panicing at all:widestring-rs/src/ucstring.rs
Lines 587 to 597 in e7236b6
calls:
widestring-rs/src/ucstring.rs
Lines 181 to 191 in e7236b6
Should I create a PR for UCStr to try and return
&[UChar::NUL]
for the length 0 case? (Maybe UCStr can gain aDefault
impl?)Should it scan/truncate too (would change the result of
str.len()
)? Perhaps matching function signatures?The inconsistent "Safety" vs "Panics" documentation crops up in multiple places - should I try and drop this text from all the "Safety" sections where
p
is already null-checked soundly and documented to be null-checked under "Panics"?The text was updated successfully, but these errors were encountered: