mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-31 13:52:08 +00:00
Improve 'RawStr' percent encoding doctests.
This commit is contained in:
parent
f058f6e01d
commit
ea0a1af683
@ -258,19 +258,9 @@ impl RawStr {
|
|||||||
/// # extern crate rocket;
|
/// # extern crate rocket;
|
||||||
/// use rocket::http::RawStr;
|
/// use rocket::http::RawStr;
|
||||||
///
|
///
|
||||||
/// let raw_str = RawStr::new("Hello%21");
|
/// let raw_str = RawStr::new("Hello/goodbye");
|
||||||
/// let decoded = raw_str.percent_decode();
|
/// let encoded = raw_str.percent_encode();
|
||||||
/// assert_eq!(decoded, Ok("Hello!".into()));
|
/// assert_eq!(encoded.as_str(), "Hello%2Fgoodbye");
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// With an invalid string:
|
|
||||||
///
|
|
||||||
/// ```rust
|
|
||||||
/// # extern crate rocket;
|
|
||||||
/// use rocket::http::RawStr;
|
|
||||||
///
|
|
||||||
/// let bad_raw_str = RawStr::new("%FF");
|
|
||||||
/// assert!(bad_raw_str.percent_decode().is_err());
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn percent_encode(&self) -> Cow<'_, RawStr> {
|
pub fn percent_encode(&self) -> Cow<'_, RawStr> {
|
||||||
@ -288,6 +278,7 @@ impl RawStr {
|
|||||||
/// // Note: Rocket should never hand you a bad `&RawStr`.
|
/// // Note: Rocket should never hand you a bad `&RawStr`.
|
||||||
/// let bytes = &[93, 12, 0, 13, 1];
|
/// let bytes = &[93, 12, 0, 13, 1];
|
||||||
/// let encoded = RawStr::percent_encode_bytes(&bytes[..]);
|
/// let encoded = RawStr::percent_encode_bytes(&bytes[..]);
|
||||||
|
/// assert_eq!(encoded.as_str(), "]%0C%00%0D%01");
|
||||||
/// ```
|
/// ```
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn percent_encode_bytes(bytes: &[u8]) -> Cow<'_, RawStr> {
|
pub fn percent_encode_bytes(bytes: &[u8]) -> Cow<'_, RawStr> {
|
||||||
|
Loading…
Reference in New Issue
Block a user