mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-23 22:51:07 +01:00
slice_ref doc tweaks
This commit is contained in:
parent
363984ad75
commit
6061a44a22
@ -51,30 +51,29 @@ impl ByteString {
|
|||||||
Self(src)
|
Self(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a slice of self that is equivalent to the given `subset`. Corresponds to [`Bytes::slice_ref`].
|
/// Returns a byte string that is equivalent to the given `subset`.
|
||||||
///
|
///
|
||||||
/// When processing a `ByteString` buffer with other tools, one often gets a
|
/// When processing a `ByteString` buffer with other tools, one often gets a `&str` which is in
|
||||||
/// `&str` which is in fact a slice of the `ByteString`, i.e. a subset of it.
|
/// fact a slice of the `ByteString`; i.e., a subset of it. This function turns that `&str` into
|
||||||
/// This function turns that `&str` into another `ByteString`, as if one had
|
/// another `ByteString`, as if one had sliced the `ByteString` with the offsets that correspond
|
||||||
/// sliced the `ByteString` with the offsets that correspond to `subset`.
|
/// to `subset`.
|
||||||
|
///
|
||||||
|
/// Corresponds to [`Bytes::slice_ref`].
|
||||||
///
|
///
|
||||||
/// This operation is `O(1)`.
|
/// This operation is `O(1)`.
|
||||||
///
|
///
|
||||||
|
/// # Panics
|
||||||
|
/// Requires that the given `subset` str is in fact contained within the `ByteString` buffer;
|
||||||
|
/// otherwise this function will panic.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
/// use bytestring::ByteString;
|
/// # use bytestring::ByteString;
|
||||||
///
|
|
||||||
/// let string = ByteString::from_static(" foo ");
|
/// let string = ByteString::from_static(" foo ");
|
||||||
/// let subset = string.trim();
|
/// let subset = string.trim();
|
||||||
/// let substring = string.slice_ref(subset);
|
/// let substring = string.slice_ref(subset);
|
||||||
/// assert_eq!(substring, "foo");
|
/// assert_eq!(substring, "foo");
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// Requires that the given `subset` str is in fact contained within the
|
|
||||||
/// `ByteString` buffer; otherwise this function will panic.
|
|
||||||
pub fn slice_ref(&self, subset: &str) -> Self {
|
pub fn slice_ref(&self, subset: &str) -> Self {
|
||||||
Self(self.0.slice_ref(subset.as_bytes()))
|
Self(self.0.slice_ref(subset.as_bytes()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user