Struct hyper::header::UserAgent
[−]
[src]
pub struct UserAgent(pub String);
User-Agent
header, defined in
RFC7231
The User-Agent
header field contains information about the user
agent originating the request, which is often used by servers to help
identify the scope of reported interoperability problems, to work
around or tailor responses to avoid particular user agent
limitations, and for analytics regarding browser or operating system
use. A user agent SHOULD send a User-Agent field in each request
unless specifically configured not to do so.
ABNF
User-Agent = product *( RWS ( product / comment ) )
product = token ["/" product-version]
product-version = token
Example values
CERN-LineMode/2.15 libwww/2.17b3
Bunnies
Notes
- The parser does not split the value
Example
use hyper::header::{Headers, UserAgent}; let mut headers = Headers::new(); headers.set(UserAgent("hyper/0.5.2".to_owned()));
Methods from Deref<Target=String>
fn into_bytes(self) -> Vec<u8>
1.0.0
Converts a String
into a byte vector.
This consumes the String
, so we do not need to copy its contents.
Examples
Basic usage:
let s = String::from("hello"); let bytes = s.into_bytes(); assert_eq!(&[104, 101, 108, 108, 111][..], &bytes[..]);
fn as_str(&self) -> &str
1.7.0
Extracts a string slice containing the entire string.
fn as_mut_str(&mut self) -> &mut str
1.7.0
Extracts a string slice containing the entire string.
fn push_str(&mut self, string: &str)
1.0.0
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);
fn capacity(&self) -> usize
1.0.0
Returns this String
's capacity, in bytes.
Examples
Basic usage:
let s = String::with_capacity(10); assert!(s.capacity() >= 10);
fn reserve(&mut self, additional: usize)
1.0.0
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 may 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());
fn reserve_exact(&mut self, additional: usize)
1.0.0
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 may 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());
fn shrink_to_fit(&mut self)
1.0.0
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());
fn push(&mut self, ch: char)
1.0.0
Appends the given char
to the end of this String
.
Examples
Basic usage:
let mut s = String::from("abc"); s.push('1'); s.push('2'); s.push('3'); assert_eq!("abc123", s);
fn as_bytes(&self) -> &[u8]
1.0.0
Returns a byte slice of this String
's contents.
Examples
Basic usage:
let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());
fn truncate(&mut self, new_len: usize)
1.0.0
Shortens this String
to the specified length.
If new_len
is greater than the string's current length, this has no
effect.
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);
fn pop(&mut self) -> Option<char>
1.0.0
Removes the last character from the string buffer and returns it.
Returns None
if this String
is empty.
Examples
Basic usage:
let mut s = String::from("foo"); assert_eq!(s.pop(), Some('o')); assert_eq!(s.pop(), Some('o')); assert_eq!(s.pop(), Some('f')); assert_eq!(s.pop(), None);
fn remove(&mut self, idx: usize) -> char
1.0.0
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');
fn insert(&mut self, idx: usize, ch: char)
1.0.0
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);
fn insert_str(&mut self, idx: usize, string: &str)
insert_str
): recent addition
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:
#![feature(insert_str)] let mut s = String::from("bar"); s.insert_str(0, "foo"); assert_eq!("foobar", s);
unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>
1.0.0
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");
fn len(&self) -> usize
1.0.0
Returns the length of this String
, in bytes.
Examples
Basic usage:
let a = String::from("foo"); assert_eq!(a.len(), 3);
fn is_empty(&self) -> bool
1.0.0
Returns true
if this String
has a length of zero.
Returns false
otherwise.
Examples
Basic usage:
let mut v = String::new(); assert!(v.is_empty()); v.push('a'); assert!(!v.is_empty());
fn split_off(&mut self, mid: usize) -> String
string_split_off
)Divide one string into two at an index.
The argument, mid
, should be a byte offset from the start of the string. It must also
be on the boundary of a UTF-8 code point.
The two strings returned go from the start of the string to mid
, and from mid
to the end
of the string.
Panics
Panics if mid
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!");
fn clear(&mut self)
1.0.0
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());
fn drain<R>(&mut self, range: R) -> Drain where R: RangeArgument<usize>
1.6.0
Create 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, "");
fn into_boxed_str(self) -> Box<str>
1.4.0
Converts this String
into a Box<str>
.
This will drop any excess capacity.
Examples
Basic usage:
let s = String::from("hello"); let b = s.into_boxed_str();
Trait Implementations
impl Clone for UserAgent
[src]
fn clone(&self) -> UserAgent
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for UserAgent
[src]
impl PartialEq for UserAgent
[src]
fn eq(&self, __arg_0: &UserAgent) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &UserAgent) -> bool
This method tests for !=
.
impl Deref for UserAgent
[src]
type Target = String
The resulting type after dereferencing
fn deref(&self) -> &String
The method called to dereference a value
impl DerefMut for UserAgent
[src]
impl Header for UserAgent
[src]
fn header_name() -> &'static str
Returns the name of the header field this belongs to. Read more
fn parse_header(raw: &[Vec<u8>]) -> Result<Self>
Parse a header from a raw stream of bytes. Read more
impl HeaderFormat for UserAgent
[src]
fn fmt_header(&self, f: &mut Formatter) -> Result
Format a header to be output into a TcpStream. Read more