From 6061a44a22dffe82b164b8cfc869931417e5646d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 7 Nov 2022 20:21:57 +0000 Subject: [PATCH] slice_ref doc tweaks --- bytestring/src/lib.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bytestring/src/lib.rs b/bytestring/src/lib.rs index 06117d7c..7058c106 100644 --- a/bytestring/src/lib.rs +++ b/bytestring/src/lib.rs @@ -51,30 +51,29 @@ impl ByteString { 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 - /// `&str` which is in fact a slice of the `ByteString`, i.e. a subset of it. - /// This function turns that `&str` into another `ByteString`, as if one had - /// sliced the `ByteString` with the offsets that correspond to `subset`. + /// When processing a `ByteString` buffer with other tools, one often gets a `&str` which is in + /// fact a slice of the `ByteString`; i.e., a subset of it. This function turns that `&str` into + /// another `ByteString`, as if one had sliced the `ByteString` with the offsets that correspond + /// to `subset`. + /// + /// Corresponds to [`Bytes::slice_ref`]. /// /// 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 - /// /// ``` - /// use bytestring::ByteString; - /// + /// # use bytestring::ByteString; /// let string = ByteString::from_static(" foo "); /// let subset = string.trim(); /// let substring = string.slice_ref(subset); /// 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 { Self(self.0.slice_ref(subset.as_bytes())) }