Struct rocket_http::hyper::header::Referer [−][src]
pub struct Referer(pub String);
Expand description
Referer
header, defined in
RFC7231
The Referer
[sic] header field allows the user agent to specify a
URI reference for the resource from which the target URI was obtained
(i.e., the “referrer”, though the field name is misspelled). A user
agent MUST NOT include the fragment and userinfo components of the
URI reference, if any, when generating the Referer field value.
ABNF
Referer = absolute-URI / partial-URI
Example values
http://www.example.org/hypertext/Overview.html
Examples
use hyper::header::{Headers, Referer};
let mut headers = Headers::new();
headers.set(Referer("/People.html#tim".to_owned()));
use hyper::header::{Headers, Referer};
let mut headers = Headers::new();
headers.set(Referer("http://www.example.com/index.html".to_owned()));
Tuple Fields
0: String
Methods from Deref<Target = String>
Extracts a string slice containing the entire String
.
Examples
Basic usage:
let s = String::from("foo");
assert_eq!("foo", s.as_str());
Converts a String
into a mutable string slice.
Examples
Basic usage:
let mut s = String::from("foobar");
let s_mut_str = s.as_mut_str();
s_mut_str.make_ascii_uppercase();
assert_eq!("FOOBAR", s_mut_str);
Appends a given string slice onto the end of this String
.
Examples
Basic usage:
let mut s = String::from("foo");
s.push_str("bar");
assert_eq!("foobar", s);
🔬 This is a nightly-only experimental API. (string_extend_from_within
)
string_extend_from_within
)Copies elements from src
range to the end of the string.
Panics
Panics if the starting point or end point do not lie on a char
boundary, or if they’re out of bounds.
Examples
#![feature(string_extend_from_within)]
let mut string = String::from("abcde");
string.extend_from_within(2..);
assert_eq!(string, "abcdecde");
string.extend_from_within(..2);
assert_eq!(string, "abcdecdeab");
string.extend_from_within(4..8);
assert_eq!(string, "abcdecdeabecde");
Returns this String
’s capacity, in bytes.
Examples
Basic usage:
let s = String::with_capacity(10);
assert!(s.capacity() >= 10);
Ensures that this String
’s capacity is at least additional
bytes
larger than its length.
The capacity may be increased by more than additional
bytes if it
chooses, to prevent frequent reallocations.
If you do not want this “at least” behavior, see the reserve_exact
method.
Panics
Panics if the new capacity overflows usize
.
Examples
Basic usage:
let mut s = String::new();
s.reserve(10);
assert!(s.capacity() >= 10);
This might not actually increase the capacity:
let mut s = String::with_capacity(10);
s.push('a');
s.push('b');
// s now has a length of 2 and a capacity of 10
assert_eq!(2, s.len());
assert_eq!(10, s.capacity());
// Since we already have an extra 8 capacity, calling this...
s.reserve(8);
// ... doesn't actually increase.
assert_eq!(10, s.capacity());
Ensures that this String
’s capacity is additional
bytes
larger than its length.
Consider using the reserve
method unless you absolutely know
better than the allocator.
Panics
Panics if the new capacity overflows usize
.
Examples
Basic usage:
let mut s = String::new();
s.reserve_exact(10);
assert!(s.capacity() >= 10);
This might not actually increase the capacity:
let mut s = String::with_capacity(10);
s.push('a');
s.push('b');
// s now has a length of 2 and a capacity of 10
assert_eq!(2, s.len());
assert_eq!(10, s.capacity());
// Since we already have an extra 8 capacity, calling this...
s.reserve_exact(8);
// ... doesn't actually increase.
assert_eq!(10, s.capacity());
🔬 This is a nightly-only experimental API. (try_reserve
)
new API
🔬 This is a nightly-only experimental API. (try_reserve
)
new API
Tries to reserve capacity for at least additional
more elements to be inserted
in the given String
. The collection may reserve more space to avoid
frequent reallocations. After calling reserve
, capacity will be
greater than or equal to self.len() + additional
. Does nothing if
capacity is already sufficient.
Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Examples
#![feature(try_reserve)]
use std::collections::TryReserveError;
fn process_data(data: &str) -> Result<String, TryReserveError> {
let mut output = String::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve(data.len())?;
// Now we know this can't OOM in the middle of our complex work
output.push_str(data);
Ok(output)
}
🔬 This is a nightly-only experimental API. (try_reserve
)
new API
🔬 This is a nightly-only experimental API. (try_reserve
)
new API
Tries to reserve the minimum capacity for exactly additional
more elements to
be inserted in the given String
. After calling reserve_exact
,
capacity will be greater than or equal to self.len() + additional
.
Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it
requests. Therefore, capacity can not be relied upon to be precisely
minimal. Prefer reserve
if future insertions are expected.
Errors
If the capacity overflows, or the allocator reports a failure, then an error is returned.
Examples
#![feature(try_reserve)]
use std::collections::TryReserveError;
fn process_data(data: &str) -> Result<String, TryReserveError> {
let mut output = String::new();
// Pre-reserve the memory, exiting if we can't
output.try_reserve(data.len())?;
// Now we know this can't OOM in the middle of our complex work
output.push_str(data);
Ok(output)
}
Shrinks the capacity of this String
to match its length.
Examples
Basic usage:
let mut s = String::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to_fit();
assert_eq!(3, s.capacity());
Shrinks the capacity of this String
with a lower bound.
The capacity will remain at least as large as both the length and the supplied value.
If the current capacity is less than the lower limit, this is a no-op.
Examples
let mut s = String::from("foo");
s.reserve(100);
assert!(s.capacity() >= 100);
s.shrink_to(10);
assert!(s.capacity() >= 10);
s.shrink_to(0);
assert!(s.capacity() >= 3);
Shortens this String
to the specified length.
If new_len
is greater than the string’s current length, this has no
effect.
Note that this method has no effect on the allocated capacity of the string
Panics
Panics if new_len
does not lie on a char
boundary.
Examples
Basic usage:
let mut s = String::from("hello");
s.truncate(2);
assert_eq!("he", s);
Removes a char
from this String
at a byte position and returns it.
This is an O(n) operation, as it requires copying every element in the buffer.
Panics
Panics if idx
is larger than or equal to the String
’s length,
or if it does not lie on a char
boundary.
Examples
Basic usage:
let mut s = String::from("foo");
assert_eq!(s.remove(0), 'f');
assert_eq!(s.remove(1), 'o');
assert_eq!(s.remove(0), 'o');
🔬 This is a nightly-only experimental API. (string_remove_matches
)
new API
🔬 This is a nightly-only experimental API. (string_remove_matches
)
new API
Remove all matches of pattern pat
in the String
.
Examples
#![feature(string_remove_matches)]
let mut s = String::from("Trees are not green, the sky is not blue.");
s.remove_matches("not ");
assert_eq!("Trees are green, the sky is blue.", s);
Matches will be detected and removed iteratively, so in cases where patterns overlap, only the first pattern will be removed:
#![feature(string_remove_matches)]
let mut s = String::from("banana");
s.remove_matches("ana");
assert_eq!("bna", s);
Retains only the characters specified by the predicate.
In other words, remove all characters c
such that f(c)
returns false
.
This method operates in place, visiting each character exactly once in the
original order, and preserves the order of the retained characters.
Examples
let mut s = String::from("f_o_ob_ar");
s.retain(|c| c != '_');
assert_eq!(s, "foobar");
Because the elements are visited exactly once in the original order, external state may be used to decide which elements to keep.
let mut s = String::from("abcde");
let keep = [false, true, true, false, true];
let mut iter = keep.iter();
s.retain(|_| *iter.next().unwrap());
assert_eq!(s, "bce");
Inserts a character into this String
at a byte position.
This is an O(n) operation as it requires copying every element in the buffer.
Panics
Panics if idx
is larger than the String
’s length, or if it does not
lie on a char
boundary.
Examples
Basic usage:
let mut s = String::with_capacity(3);
s.insert(0, 'f');
s.insert(1, 'o');
s.insert(2, 'o');
assert_eq!("foo", s);
Inserts a string slice into this String
at a byte position.
This is an O(n) operation as it requires copying every element in the buffer.
Panics
Panics if idx
is larger than the String
’s length, or if it does not
lie on a char
boundary.
Examples
Basic usage:
let mut s = String::from("bar");
s.insert_str(0, "foo");
assert_eq!("foobar", s);
Returns a mutable reference to the contents of this String
.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid UTF-8. If this constraint is violated, it may cause
memory unsafety issues with future users of the String
, as the rest of
the standard library assumes that String
s are valid UTF-8.
Examples
Basic usage:
let mut s = String::from("hello");
unsafe {
let vec = s.as_mut_vec();
assert_eq!(&[104, 101, 108, 108, 111][..], &vec[..]);
vec.reverse();
}
assert_eq!(s, "olleh");
Returns the length of this String
, in bytes, not char
s or
graphemes. In other words, it might not be what a human considers the
length of the string.
Examples
Basic usage:
let a = String::from("foo");
assert_eq!(a.len(), 3);
let fancy_f = String::from("ƒoo");
assert_eq!(fancy_f.len(), 4);
assert_eq!(fancy_f.chars().count(), 3);
Returns true
if this String
has a length of zero, and false
otherwise.
Examples
Basic usage:
let mut v = String::new();
assert!(v.is_empty());
v.push('a');
assert!(!v.is_empty());
Splits the string into two at the given byte index.
Returns a newly allocated String
. self
contains bytes [0, at)
, and
the returned String
contains bytes [at, len)
. at
must be on the
boundary of a UTF-8 code point.
Note that the capacity of self
does not change.
Panics
Panics if at
is not on a UTF-8
code point boundary, or if it is beyond the last
code point of the string.
Examples
let mut hello = String::from("Hello, World!");
let world = hello.split_off(7);
assert_eq!(hello, "Hello, ");
assert_eq!(world, "World!");
Truncates this String
, removing all contents.
While this means the String
will have a length of zero, it does not
touch its capacity.
Examples
Basic usage:
let mut s = String::from("foo");
s.clear();
assert!(s.is_empty());
assert_eq!(0, s.len());
assert_eq!(3, s.capacity());
Creates a draining iterator that removes the specified range in the String
and yields the removed chars
.
Note: The element range is removed even if the iterator is not consumed until the end.
Panics
Panics if the starting point or end point do not lie on a char
boundary, or if they’re out of bounds.
Examples
Basic usage:
let mut s = String::from("α is alpha, β is beta");
let beta_offset = s.find('β').unwrap_or(s.len());
// Remove the range up until the β from the string
let t: String = s.drain(..beta_offset).collect();
assert_eq!(t, "α is alpha, ");
assert_eq!(s, "β is beta");
// A full range clears the string
s.drain(..);
assert_eq!(s, "");
1.27.0[src]pub fn replace_range<R>(&mut self, range: R, replace_with: &str) where
R: RangeBounds<usize>,
pub fn replace_range<R>(&mut self, range: R, replace_with: &str) where
R: RangeBounds<usize>,
Removes the specified range in the string, and replaces it with the given string. The given string doesn’t need to be the same length as the range.
Panics
Panics if the starting point or end point do not lie on a char
boundary, or if they’re out of bounds.
Examples
Basic usage:
let mut s = String::from("α is alpha, β is beta");
let beta_offset = s.find('β').unwrap_or(s.len());
// Replace the range up until the β from the string
s.replace_range(..beta_offset, "Α is capital alpha; ");
assert_eq!(s, "Α is capital alpha; β is beta");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Referer
impl UnwindSafe for Referer
Blanket Implementations
Mutably borrows from an owned value. Read more