1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 00:01:11 +01:00

slice_ref doc tweaks

This commit is contained in:
Rob Ede 2022-11-07 20:21:57 +00:00
parent 363984ad75
commit 6061a44a22
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933

View File

@ -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()))
} }