-
Notifications
You must be signed in to change notification settings - Fork 79
Byte-oriented methods for ngx_str_t
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Added a couple of small questions.
/// # Safety | ||
/// | ||
/// The caller must provide a valid pointer to a memory pool. | ||
pub unsafe fn from_bytes(pool: *mut ngx_pool_t, src: &[u8]) -> Option<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from_string()
and from_str()
, both return Self, not Option<Self>
, shouldn't we change them as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's worth fixing the str
conversion functions. I planned to remove these or at least mark as deprecated.
Use unaligned allocations for strings.
A zero-length `ngx_str_t` is still valid, but the data pointer is not guaranteed to be valid or initialized in that case.
There's no guarantee we'll be working with a valid UTF-8 data.
e9c0afb
to
46e01bd
Compare
`size_t` is transformed to `usize` by default since bindgen 0.61. As we require much newer version of bindgen, the explicit casts are no longer necessary.
46e01bd
to
cb7e21d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
ngx_str_t
likely does not contain UTF-8, so converting it from/to UTF-8 strings is expensive and useless.from_bytes()
andas_bytes()
should be a more appropriate interface.At some point in the future I intend to drop the
String
/&str
conversion methods, as these aren't safe.