(function() {var type_impls = { "form_urlencoded":[["
source§

impl<T> Option<T>

1.0.0 (const: 1.48.0) · source

pub const fn is_some(&self) -> bool

Returns true if the option is a Some value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some(), true);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some(), false);
\n
1.70.0 · source

pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a Some and the value inside of it matches a predicate.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some_and(|x| x > 1), true);\n\nlet x: Option<u32> = Some(0);\nassert_eq!(x.is_some_and(|x| x > 1), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some_and(|x| x > 1), false);
\n
1.0.0 (const: 1.48.0) · source

pub const fn is_none(&self) -> bool

Returns true if the option is a None value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_none(), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_none(), true);
\n
1.0.0 (const: 1.48.0) · source

pub const fn as_ref(&self) -> Option<&T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Calculates the length of an Option<String> as an Option<usize>\nwithout moving the String. The map method takes the self argument by value,\nconsuming the original, so this technique uses as_ref to first take an Option to a\nreference to the value inside the original.

\n\n
let text: Option<String> = Some(\"Hello, world!\".to_string());\n// First, cast `Option<String>` to `Option<&String>` with `as_ref`,\n// then consume *that* with `map`, leaving `text` on the stack.\nlet text_length: Option<usize> = text.as_ref().map(|s| s.len());\nprintln!(\"still can print text: {text:?}\");
\n
1.0.0 (const: unstable) · source

pub fn as_mut(&mut self) -> Option<&mut T>

Converts from &mut Option<T> to Option<&mut T>.

\n
Examples
\n
let mut x = Some(2);\nmatch x.as_mut() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));
\n
1.33.0 (const: unstable) · source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

\n
1.33.0 (const: unstable) · source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

\n
1.75.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an\nempty slice is returned. This can be useful to have a single type of\niterator over an Option or slice.

\n

Note: Should you have an Option<&T> and wish to get a slice of T,\nyou can unpack it via opt.map_or(&[], std::slice::from_ref).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_slice(), None.as_slice()],\n    [&[1234][..], &[][..]],\n);
\n

The inverse of this function is (discounting\nborrowing) [_]::first:

\n\n
for i in [Some(1234_u16), None] {\n    assert_eq!(i.as_ref(), i.as_slice().first());\n}
\n
1.75.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is\nNone, an empty slice is returned. This can be useful to have a\nsingle type of iterator over an Option or slice.

\n

Note: Should you have an Option<&mut T> instead of a\n&mut Option<T>, which this method takes, you can obtain a mutable\nslice via opt.map_or(&mut [], std::slice::from_mut).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_mut_slice(), None.as_mut_slice()],\n    [&mut [1234][..], &mut [][..]],\n);
\n

The result is a mutable slice of zero or one items that points into\nour original Option:

\n\n
let mut x = Some(1234);\nx.as_mut_slice()[0] += 1;\nassert_eq!(x, Some(1235));
\n

The inverse of this method (discounting borrowing)\nis [_]::first_mut:

\n\n
assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
\n
1.0.0 (const: unstable) · source

pub fn expect(self, msg: &str) -> T

Returns the contained Some value, consuming the self value.

\n
Panics
\n

Panics if the value is a None with a custom panic message provided by\nmsg.

\n
Examples
\n
let x = Some(\"value\");\nassert_eq!(x.expect(\"fruits are healthy\"), \"value\");
\n\n
let x: Option<&str> = None;\nx.expect(\"fruits are healthy\"); // panics with `fruits are healthy`
\n
Recommended Message Style
\n

We recommend that expect messages are used to describe the reason you\nexpect the Option should be Some.

\n\n
let item = slice.get(0)\n    .expect(\"slice should not be empty\");
\n

Hint: If you’re having trouble remembering how to phrase expect\nerror messages remember to focus on the word “should” as in “env\nvariable should be set by blah” or “the given binary should be available\nand executable by the current user”.

\n

For more detail on expect message styles and the reasoning behind our\nrecommendation please refer to the section on “Common Message\nStyles” in the std::error module docs.

\n
1.0.0 (const: unstable) · source

pub fn unwrap(self) -> T

Returns the contained Some value, consuming the self value.

\n

Because this function may panic, its use is generally discouraged.\nInstead, prefer to use pattern matching and handle the None\ncase explicitly, or call unwrap_or, unwrap_or_else, or\nunwrap_or_default.

\n
Panics
\n

Panics if the self value equals None.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(x.unwrap(), \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(x.unwrap(), \"air\"); // fails
\n
1.0.0 · source

pub fn unwrap_or(self, default: T) -> T

Returns the contained Some value or a provided default.

\n

Arguments passed to unwrap_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use unwrap_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
assert_eq!(Some(\"car\").unwrap_or(\"bike\"), \"car\");\nassert_eq!(None.unwrap_or(\"bike\"), \"bike\");
\n
1.0.0 · source

pub fn unwrap_or_else<F>(self, f: F) -> T
where\n F: FnOnce() -> T,

Returns the contained Some value or computes it from a closure.

\n
Examples
\n
let k = 10;\nassert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);\nassert_eq!(None.unwrap_or_else(|| 2 * k), 20);
\n
1.0.0 · source

pub fn unwrap_or_default(self) -> T
where\n T: Default,

Returns the contained Some value or a default.

\n

Consumes the self argument then, if Some, returns the contained\nvalue, otherwise if None, returns the default value for that\ntype.

\n
Examples
\n
let x: Option<u32> = None;\nlet y: Option<u32> = Some(12);\n\nassert_eq!(x.unwrap_or_default(), 0);\nassert_eq!(y.unwrap_or_default(), 12);
\n
1.58.0 (const: unstable) · source

pub unsafe fn unwrap_unchecked(self) -> T

Returns the contained Some value, consuming the self value,\nwithout checking that the value is not None.

\n
Safety
\n

Calling this method on None is undefined behavior.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\"); // Undefined behavior!
\n
1.0.0 · source

pub fn map<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> U,

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

\n
Examples
\n

Calculates the length of an Option<String> as an\nOption<usize>, consuming the original:

\n\n
let maybe_some_string = Some(String::from(\"Hello, World!\"));\n// `Option::map` takes self *by value*, consuming `maybe_some_string`\nlet maybe_some_len = maybe_some_string.map(|s| s.len());\nassert_eq!(maybe_some_len, Some(13));\n\nlet x: Option<&str> = None;\nassert_eq!(x.map(|s| s.len()), None);
\n
1.76.0 · source

pub fn inspect<F>(self, f: F) -> Option<T>
where\n F: FnOnce(&T),

Calls the provided closure with a reference to the contained value (if Some).

\n
Examples
\n
let v = vec![1, 2, 3, 4, 5];\n\n// prints \"got: 4\"\nlet x: Option<&usize> = v.get(3).inspect(|x| println!(\"got: {x}\"));\n\n// prints nothing\nlet x: Option<&usize> = v.get(5).inspect(|x| println!(\"got: {x}\"));
\n
1.0.0 · source

pub fn map_or<U, F>(self, default: U, f: F) -> U
where\n F: FnOnce(T) -> U,

Returns the provided default result (if none),\nor applies a function to the contained value (if any).

\n

Arguments passed to map_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use map_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.map_or(42, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or(42, |v| v.len()), 42);
\n
1.0.0 · source

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where\n D: FnOnce() -> U,\n F: FnOnce(T) -> U,

Computes a default function result (if none), or\napplies a different function to the contained value (if any).

\n
Basic examples
\n
let k = 21;\n\nlet x = Some(\"foo\");\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
\n
Handling a Result-based fallback
\n

A somewhat common occurrence when dealing with optional values\nin combination with Result<T, E> is the case where one wants to invoke\na fallible fallback if the option is not present. This example\nparses a command line argument (if present), or the contents of a file to\nan integer. However, unlike accessing the command line argument, reading\nthe file is fallible, so it must be wrapped with Ok.

\n\n
let v: u64 = std::env::args()\n   .nth(1)\n   .map_or_else(|| std::fs::read_to_string(\"/etc/someconfig.conf\"), Ok)?\n   .parse()?;
\n
1.0.0 · source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err).

\n

Arguments passed to ok_or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use ok_or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or(0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or(0), Err(0));
\n
1.0.0 · source

pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where\n F: FnOnce() -> E,

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err()).

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or_else(|| 0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or_else(|| 0), Err(0));
\n
1.40.0 · source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where\n T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

\n

Leaves the original Option in-place, creating a new one with a reference\nto the original one, additionally coercing the contents via Deref.

\n
Examples
\n
let x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref(), Some(\"hey\"));\n\nlet x: Option<String> = None;\nassert_eq!(x.as_deref(), None);
\n
1.40.0 · source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where\n T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

\n

Leaves the original Option in-place, creating a new one containing a mutable reference to\nthe inner type’s Deref::Target type.

\n
Examples
\n
let mut x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref_mut().map(|x| {\n    x.make_ascii_uppercase();\n    x\n}), Some(\"HEY\".to_owned().as_mut_str()));
\n
1.0.0 (const: unstable) · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

\n
Examples
\n
let x = Some(4);\nassert_eq!(x.iter().next(), Some(&4));\n\nlet x: Option<u32> = None;\nassert_eq!(x.iter().next(), None);
\n
1.0.0 · source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

\n
Examples
\n
let mut x = Some(4);\nmatch x.iter_mut().next() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));\n\nlet mut x: Option<u32> = None;\nassert_eq!(x.iter_mut().next(), None);
\n
1.0.0 · source

pub fn and<U>(self, optb: Option<U>) -> Option<U>

Returns None if the option is None, otherwise returns optb.

\n

Arguments passed to and are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use and_then, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);\n\nlet x: Option<u32> = None;\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), None);\n\nlet x = Some(2);\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), Some(\"foo\"));\n\nlet x: Option<u32> = None;\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);
\n
1.0.0 · source

pub fn and_then<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the\nwrapped value and returns the result.

\n

Some languages call this operation flatmap.

\n
Examples
\n
fn sq_then_to_string(x: u32) -> Option<String> {\n    x.checked_mul(x).map(|sq| sq.to_string())\n}\n\nassert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));\nassert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!\nassert_eq!(None.and_then(sq_then_to_string), None);
\n

Often used to chain fallible operations that may return None.

\n\n
let arr_2d = [[\"A0\", \"A1\"], [\"B0\", \"B1\"]];\n\nlet item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));\nassert_eq!(item_0_1, Some(&\"A1\"));\n\nlet item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));\nassert_eq!(item_2_0, None);
\n
1.27.0 · source

pub fn filter<P>(self, predicate: P) -> Option<T>
where\n P: FnOnce(&T) -> bool,

Returns None if the option is None, otherwise calls predicate\nwith the wrapped value and returns:

\n
    \n
  • Some(t) if predicate returns true (where t is the wrapped\nvalue), and
  • \n
  • None if predicate returns false.
  • \n
\n

This function works similar to Iterator::filter(). You can imagine\nthe Option<T> being an iterator over one or zero elements. filter()\nlets you decide which elements to keep.

\n
Examples
\n
fn is_even(n: &i32) -> bool {\n    n % 2 == 0\n}\n\nassert_eq!(None.filter(is_even), None);\nassert_eq!(Some(3).filter(is_even), None);\nassert_eq!(Some(4).filter(is_even), Some(4));
\n
1.0.0 · source

pub fn or(self, optb: Option<T>) -> Option<T>

Returns the option if it contains a value, otherwise returns optb.

\n

Arguments passed to or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y = None;\nassert_eq!(x.or(y), Some(2));\n\nlet x = None;\nlet y = Some(100);\nassert_eq!(x.or(y), Some(100));\n\nlet x = Some(2);\nlet y = Some(100);\nassert_eq!(x.or(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = None;\nassert_eq!(x.or(y), None);
\n
1.0.0 · source

pub fn or_else<F>(self, f: F) -> Option<T>
where\n F: FnOnce() -> Option<T>,

Returns the option if it contains a value, otherwise calls f and\nreturns the result.

\n
Examples
\n
fn nobody() -> Option<&'static str> { None }\nfn vikings() -> Option<&'static str> { Some(\"vikings\") }\n\nassert_eq!(Some(\"barbarians\").or_else(vikings), Some(\"barbarians\"));\nassert_eq!(None.or_else(vikings), Some(\"vikings\"));\nassert_eq!(None.or_else(nobody), None);
\n
1.37.0 · source

pub fn xor(self, optb: Option<T>) -> Option<T>

Returns Some if exactly one of self, optb is Some, otherwise returns None.

\n
Examples
\n
let x = Some(2);\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = Some(2);\nassert_eq!(x.xor(y), Some(2));\n\nlet x = Some(2);\nlet y = Some(2);\nassert_eq!(x.xor(y), None);\n\nlet x: Option<u32> = None;\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), None);
\n
1.53.0 · source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

\n

If the option already contains a value, the old value is dropped.

\n

See also Option::get_or_insert, which doesn’t update the value if\nthe option already contains Some.

\n
Example
\n
let mut opt = None;\nlet val = opt.insert(1);\nassert_eq!(*val, 1);\nassert_eq!(opt.unwrap(), 1);\nlet val = opt.insert(2);\nassert_eq!(*val, 2);\n*val = 3;\nassert_eq!(opt.unwrap(), 3);
\n
1.20.0 · source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n

See also Option::insert, which updates the value even if\nthe option already contains Some.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert(5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
source

pub fn get_or_insert_default(&mut self) -> &mut T
where\n T: Default,

🔬This is a nightly-only experimental API. (option_get_or_insert_default)

Inserts the default value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n
Examples
\n
#![feature(option_get_or_insert_default)]\n\nlet mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_default();\n    assert_eq!(y, &0);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.20.0 · source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where\n F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None,\nthen returns a mutable reference to the contained value.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_with(|| 5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.0.0 (const: unstable) · source

pub fn take(&mut self) -> Option<T>

Takes the value out of the option, leaving a None in its place.

\n
Examples
\n
let mut x = Some(2);\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, Some(2));\n\nlet mut x: Option<u32> = None;\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, None);
\n
source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where\n P: FnOnce(&mut T) -> bool,

🔬This is a nightly-only experimental API. (option_take_if)

Takes the value out of the option, but only if the predicate evaluates to\ntrue on a mutable reference to the value.

\n

In other words, replaces self with None if the predicate returns true.\nThis method operates similar to Option::take but conditional.

\n
Examples
\n
#![feature(option_take_if)]\n\nlet mut x = Some(42);\n\nlet prev = x.take_if(|v| if *v == 42 {\n    *v += 1;\n    false\n} else {\n    false\n});\nassert_eq!(x, Some(43));\nassert_eq!(prev, None);\n\nlet prev = x.take_if(|v| *v == 43);\nassert_eq!(x, None);\nassert_eq!(prev, Some(43));
\n
1.31.0 (const: unstable) · source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter,\nreturning the old value if present,\nleaving a Some in its place without deinitializing either one.

\n
Examples
\n
let mut x = Some(2);\nlet old = x.replace(5);\nassert_eq!(x, Some(5));\nassert_eq!(old, Some(2));\n\nlet mut x = None;\nlet old = x.replace(3);\nassert_eq!(x, Some(3));\nassert_eq!(old, None);
\n
1.46.0 · source

pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)>

Zips self with another Option.

\n

If self is Some(s) and other is Some(o), this method returns Some((s, o)).\nOtherwise, None is returned.

\n
Examples
\n
let x = Some(1);\nlet y = Some(\"hi\");\nlet z = None::<u8>;\n\nassert_eq!(x.zip(y), Some((1, \"hi\")));\nassert_eq!(x.zip(z), None);
\n
source

pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where\n F: FnOnce(T, U) -> R,

🔬This is a nightly-only experimental API. (option_zip)

Zips self and another Option with function f.

\n

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)).\nOtherwise, None is returned.

\n
Examples
\n
#![feature(option_zip)]\n\n#[derive(Debug, PartialEq)]\nstruct Point {\n    x: f64,\n    y: f64,\n}\n\nimpl Point {\n    fn new(x: f64, y: f64) -> Self {\n        Self { x, y }\n    }\n}\n\nlet x = Some(17.5);\nlet y = Some(42.7);\n\nassert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));\nassert_eq!(x.zip_with(None, Point::new), None);
\n
",0,"form_urlencoded::EncodingOverride"],["
source§

impl<T> Option<&T>

1.35.0 (const: unstable) · source

pub fn copied(self) -> Option<T>
where\n T: Copy,

Maps an Option<&T> to an Option<T> by copying the contents of the\noption.

\n
Examples
\n
let x = 12;\nlet opt_x = Some(&x);\nassert_eq!(opt_x, Some(&12));\nlet copied = opt_x.copied();\nassert_eq!(copied, Some(12));
\n
1.0.0 · source

pub fn cloned(self) -> Option<T>
where\n T: Clone,

Maps an Option<&T> to an Option<T> by cloning the contents of the\noption.

\n
Examples
\n
let x = 12;\nlet opt_x = Some(&x);\nassert_eq!(opt_x, Some(&12));\nlet cloned = opt_x.cloned();\nassert_eq!(cloned, Some(12));
\n
",0,"form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> PartialOrd for Option<T>
where\n T: PartialOrd,

source§

fn partial_cmp(&self, other: &Option<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <=\noperator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >=\noperator. Read more
","PartialOrd","form_urlencoded::EncodingOverride"],["
1.37.0 · source§

impl<T, U> Product<Option<U>> for Option<T>
where\n T: Product<U>,

source§

fn product<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the product of all elements is returned.

\n
Examples
\n

This multiplies each number in a vector of strings,\nif a string could not be parsed the operation returns None:

\n\n
let nums = vec![\"5\", \"10\", \"1\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, Some(100));\nlet nums = vec![\"5\", \"10\", \"one\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, None);
\n
","Product>","form_urlencoded::EncodingOverride"],["
source§

impl<T> FromResidual for Option<T>

source§

fn from_residual(residual: Option<Infallible>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual","form_urlencoded::EncodingOverride"],["
source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

fn from_residual(_: Yeet<()>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual>","form_urlencoded::EncodingOverride"],["
source§

impl<T> Try for Option<T>

§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

type Residual = Option<Infallible>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual\nas part of ? when short-circuiting. Read more
source§

fn from_output(output: <Option<T> as Try>::Output) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

fn branch(\n self\n) -> ControlFlow<<Option<T> as Try>::Residual, <Option<T> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value\n(because this returned ControlFlow::Continue)\nor propagate a value back to the caller\n(because this returned ControlFlow::Break). Read more
","Try","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Clone for Option<T>
where\n T: Clone,

source§

fn clone(&self) -> Option<T>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Option<T>)

Performs copy-assignment from source. Read more
","Clone","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<A, V> FromIterator<Option<A>> for Option<V>
where\n V: FromIterator<A>,

source§

fn from_iter<I>(iter: I) -> Option<V>
where\n I: IntoIterator<Item = Option<A>>,

Takes each element in the Iterator: if it is None,\nno further elements are taken, and the None is\nreturned. Should no None occur, a container of type\nV containing the values of each Option is returned.

\n
Examples
\n

Here is an example which increments every integer in a vector.\nWe use the checked variant of add that returns None when the\ncalculation would result in an overflow.

\n\n
let items = vec![0_u16, 1, 2];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_add(1))\n    .collect();\n\nassert_eq!(res, Some(vec![1, 2, 3]));
\n

As you can see, this will return the expected, valid items.

\n

Here is another example that tries to subtract one from another list\nof integers, this time checking for underflow:

\n\n
let items = vec![2_u16, 1, 0];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_sub(1))\n    .collect();\n\nassert_eq!(res, None);
\n

Since the last element is zero, it would underflow. Thus, the resulting\nvalue is None.

\n

Here is a variation on the previous example, showing that no\nfurther elements are taken from iter after the first None.

\n\n
let items = vec![3_u16, 2, 1, 10];\n\nlet mut shared = 0;\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| { shared += x; x.checked_sub(2) })\n    .collect();\n\nassert_eq!(res, None);\nassert_eq!(shared, 6);
\n

Since the third element caused an underflow, no further elements were taken,\nso the final value of shared is 6 (= 3 + 2 + 1), not 16.

\n
","FromIterator>","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> StructuralEq for Option<T>

","StructuralEq","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Eq for Option<T>
where\n T: Eq,

","Eq","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Hash for Option<T>
where\n T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where\n __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where\n H: Hasher,\n Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
","Hash","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Ord for Option<T>
where\n T: Ord,

source§

fn cmp(&self, other: &Option<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where\n Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
","Ord","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> PartialEq for Option<T>
where\n T: PartialEq,

source§

fn eq(&self, other: &Option<T>) -> bool

This method tests for self and other values to be equal, and is used\nby ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always\nsufficient, and should not be overridden without very good reason.
","PartialEq","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> IntoIterator for Option<T>

source§

fn into_iter(self) -> IntoIter<T>

Returns a consuming iterator over the possibly contained value.

\n
Examples
\n
let x = Some(\"string\");\nlet v: Vec<&str> = x.into_iter().collect();\nassert_eq!(v, [\"string\"]);\n\nlet x = None;\nlet v: Vec<&str> = x.into_iter().collect();\nassert!(v.is_empty());
\n
§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
","IntoIterator","form_urlencoded::EncodingOverride"],["
1.37.0 · source§

impl<T, U> Sum<Option<U>> for Option<T>
where\n T: Sum<U>,

source§

fn sum<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the sum of all elements is returned.

\n
Examples
\n

This sums up the position of the character ‘a’ in a vector of strings,\nif a word did not have the character ‘a’ the operation returns None:

\n\n
let words = vec![\"have\", \"a\", \"great\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, Some(5));\nlet words = vec![\"have\", \"a\", \"good\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, None);
\n
","Sum>","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> StructuralPartialEq for Option<T>

","StructuralPartialEq","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Debug for Option<T>
where\n T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","form_urlencoded::EncodingOverride"],["
1.30.0 · source§

impl<'a, T> From<&'a Option<T>> for Option<&'a T>

source§

fn from(o: &'a Option<T>) -> Option<&'a T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Converts an Option<String> into an Option<usize>, preserving\nthe original. The map method takes the self argument by value, consuming the original,\nso this technique uses from to first take an Option to a reference\nto the value inside the original.

\n\n
let s: Option<String> = Some(String::from(\"Hello, Rustaceans!\"));\nlet o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len());\n\nprintln!(\"Can still print s: {s:?}\");\n\nassert_eq!(o, Some(18));
\n
","From<&'a Option>","form_urlencoded::EncodingOverride"],["
1.12.0 · source§

impl<T> From<T> for Option<T>

source§

fn from(val: T) -> Option<T>

Moves val into a new Some.

\n
Examples
\n
let o: Option<u8> = Option::from(67);\n\nassert_eq!(Some(67), o);
\n
","From","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Copy for Option<T>
where\n T: Copy,

","Copy","form_urlencoded::EncodingOverride"],["
1.0.0 · source§

impl<T> Default for Option<T>

source§

fn default() -> Option<T>

Returns None.

\n
Examples
\n
let opt: Option<u32> = Option::default();\nassert!(opt.is_none());
\n
","Default","form_urlencoded::EncodingOverride"]], "libgit2_sys":[["
source§

impl<T> Option<T>

1.0.0 (const: 1.48.0) · source

pub const fn is_some(&self) -> bool

Returns true if the option is a Some value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some(), true);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some(), false);
\n
1.70.0 · source

pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a Some and the value inside of it matches a predicate.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some_and(|x| x > 1), true);\n\nlet x: Option<u32> = Some(0);\nassert_eq!(x.is_some_and(|x| x > 1), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some_and(|x| x > 1), false);
\n
1.0.0 (const: 1.48.0) · source

pub const fn is_none(&self) -> bool

Returns true if the option is a None value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_none(), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_none(), true);
\n
1.0.0 (const: 1.48.0) · source

pub const fn as_ref(&self) -> Option<&T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Calculates the length of an Option<String> as an Option<usize>\nwithout moving the String. The map method takes the self argument by value,\nconsuming the original, so this technique uses as_ref to first take an Option to a\nreference to the value inside the original.

\n\n
let text: Option<String> = Some(\"Hello, world!\".to_string());\n// First, cast `Option<String>` to `Option<&String>` with `as_ref`,\n// then consume *that* with `map`, leaving `text` on the stack.\nlet text_length: Option<usize> = text.as_ref().map(|s| s.len());\nprintln!(\"still can print text: {text:?}\");
\n
1.0.0 (const: unstable) · source

pub fn as_mut(&mut self) -> Option<&mut T>

Converts from &mut Option<T> to Option<&mut T>.

\n
Examples
\n
let mut x = Some(2);\nmatch x.as_mut() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));
\n
1.33.0 (const: unstable) · source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

\n
1.33.0 (const: unstable) · source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

\n
1.75.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an\nempty slice is returned. This can be useful to have a single type of\niterator over an Option or slice.

\n

Note: Should you have an Option<&T> and wish to get a slice of T,\nyou can unpack it via opt.map_or(&[], std::slice::from_ref).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_slice(), None.as_slice()],\n    [&[1234][..], &[][..]],\n);
\n

The inverse of this function is (discounting\nborrowing) [_]::first:

\n\n
for i in [Some(1234_u16), None] {\n    assert_eq!(i.as_ref(), i.as_slice().first());\n}
\n
1.75.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is\nNone, an empty slice is returned. This can be useful to have a\nsingle type of iterator over an Option or slice.

\n

Note: Should you have an Option<&mut T> instead of a\n&mut Option<T>, which this method takes, you can obtain a mutable\nslice via opt.map_or(&mut [], std::slice::from_mut).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_mut_slice(), None.as_mut_slice()],\n    [&mut [1234][..], &mut [][..]],\n);
\n

The result is a mutable slice of zero or one items that points into\nour original Option:

\n\n
let mut x = Some(1234);\nx.as_mut_slice()[0] += 1;\nassert_eq!(x, Some(1235));
\n

The inverse of this method (discounting borrowing)\nis [_]::first_mut:

\n\n
assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
\n
1.0.0 (const: unstable) · source

pub fn expect(self, msg: &str) -> T

Returns the contained Some value, consuming the self value.

\n
Panics
\n

Panics if the value is a None with a custom panic message provided by\nmsg.

\n
Examples
\n
let x = Some(\"value\");\nassert_eq!(x.expect(\"fruits are healthy\"), \"value\");
\n\n
let x: Option<&str> = None;\nx.expect(\"fruits are healthy\"); // panics with `fruits are healthy`
\n
Recommended Message Style
\n

We recommend that expect messages are used to describe the reason you\nexpect the Option should be Some.

\n\n
let item = slice.get(0)\n    .expect(\"slice should not be empty\");
\n

Hint: If you’re having trouble remembering how to phrase expect\nerror messages remember to focus on the word “should” as in “env\nvariable should be set by blah” or “the given binary should be available\nand executable by the current user”.

\n

For more detail on expect message styles and the reasoning behind our\nrecommendation please refer to the section on “Common Message\nStyles” in the std::error module docs.

\n
1.0.0 (const: unstable) · source

pub fn unwrap(self) -> T

Returns the contained Some value, consuming the self value.

\n

Because this function may panic, its use is generally discouraged.\nInstead, prefer to use pattern matching and handle the None\ncase explicitly, or call unwrap_or, unwrap_or_else, or\nunwrap_or_default.

\n
Panics
\n

Panics if the self value equals None.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(x.unwrap(), \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(x.unwrap(), \"air\"); // fails
\n
1.0.0 · source

pub fn unwrap_or(self, default: T) -> T

Returns the contained Some value or a provided default.

\n

Arguments passed to unwrap_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use unwrap_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
assert_eq!(Some(\"car\").unwrap_or(\"bike\"), \"car\");\nassert_eq!(None.unwrap_or(\"bike\"), \"bike\");
\n
1.0.0 · source

pub fn unwrap_or_else<F>(self, f: F) -> T
where\n F: FnOnce() -> T,

Returns the contained Some value or computes it from a closure.

\n
Examples
\n
let k = 10;\nassert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);\nassert_eq!(None.unwrap_or_else(|| 2 * k), 20);
\n
1.0.0 · source

pub fn unwrap_or_default(self) -> T
where\n T: Default,

Returns the contained Some value or a default.

\n

Consumes the self argument then, if Some, returns the contained\nvalue, otherwise if None, returns the default value for that\ntype.

\n
Examples
\n
let x: Option<u32> = None;\nlet y: Option<u32> = Some(12);\n\nassert_eq!(x.unwrap_or_default(), 0);\nassert_eq!(y.unwrap_or_default(), 12);
\n
1.58.0 (const: unstable) · source

pub unsafe fn unwrap_unchecked(self) -> T

Returns the contained Some value, consuming the self value,\nwithout checking that the value is not None.

\n
Safety
\n

Calling this method on None is undefined behavior.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\"); // Undefined behavior!
\n
1.0.0 · source

pub fn map<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> U,

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

\n
Examples
\n

Calculates the length of an Option<String> as an\nOption<usize>, consuming the original:

\n\n
let maybe_some_string = Some(String::from(\"Hello, World!\"));\n// `Option::map` takes self *by value*, consuming `maybe_some_string`\nlet maybe_some_len = maybe_some_string.map(|s| s.len());\nassert_eq!(maybe_some_len, Some(13));\n\nlet x: Option<&str> = None;\nassert_eq!(x.map(|s| s.len()), None);
\n
1.76.0 · source

pub fn inspect<F>(self, f: F) -> Option<T>
where\n F: FnOnce(&T),

Calls the provided closure with a reference to the contained value (if Some).

\n
Examples
\n
let v = vec![1, 2, 3, 4, 5];\n\n// prints \"got: 4\"\nlet x: Option<&usize> = v.get(3).inspect(|x| println!(\"got: {x}\"));\n\n// prints nothing\nlet x: Option<&usize> = v.get(5).inspect(|x| println!(\"got: {x}\"));
\n
1.0.0 · source

pub fn map_or<U, F>(self, default: U, f: F) -> U
where\n F: FnOnce(T) -> U,

Returns the provided default result (if none),\nor applies a function to the contained value (if any).

\n

Arguments passed to map_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use map_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.map_or(42, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or(42, |v| v.len()), 42);
\n
1.0.0 · source

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where\n D: FnOnce() -> U,\n F: FnOnce(T) -> U,

Computes a default function result (if none), or\napplies a different function to the contained value (if any).

\n
Basic examples
\n
let k = 21;\n\nlet x = Some(\"foo\");\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
\n
Handling a Result-based fallback
\n

A somewhat common occurrence when dealing with optional values\nin combination with Result<T, E> is the case where one wants to invoke\na fallible fallback if the option is not present. This example\nparses a command line argument (if present), or the contents of a file to\nan integer. However, unlike accessing the command line argument, reading\nthe file is fallible, so it must be wrapped with Ok.

\n\n
let v: u64 = std::env::args()\n   .nth(1)\n   .map_or_else(|| std::fs::read_to_string(\"/etc/someconfig.conf\"), Ok)?\n   .parse()?;
\n
1.0.0 · source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err).

\n

Arguments passed to ok_or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use ok_or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or(0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or(0), Err(0));
\n
1.0.0 · source

pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where\n F: FnOnce() -> E,

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err()).

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or_else(|| 0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or_else(|| 0), Err(0));
\n
1.40.0 · source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where\n T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

\n

Leaves the original Option in-place, creating a new one with a reference\nto the original one, additionally coercing the contents via Deref.

\n
Examples
\n
let x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref(), Some(\"hey\"));\n\nlet x: Option<String> = None;\nassert_eq!(x.as_deref(), None);
\n
1.40.0 · source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where\n T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

\n

Leaves the original Option in-place, creating a new one containing a mutable reference to\nthe inner type’s Deref::Target type.

\n
Examples
\n
let mut x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref_mut().map(|x| {\n    x.make_ascii_uppercase();\n    x\n}), Some(\"HEY\".to_owned().as_mut_str()));
\n
1.0.0 (const: unstable) · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

\n
Examples
\n
let x = Some(4);\nassert_eq!(x.iter().next(), Some(&4));\n\nlet x: Option<u32> = None;\nassert_eq!(x.iter().next(), None);
\n
1.0.0 · source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

\n
Examples
\n
let mut x = Some(4);\nmatch x.iter_mut().next() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));\n\nlet mut x: Option<u32> = None;\nassert_eq!(x.iter_mut().next(), None);
\n
1.0.0 · source

pub fn and<U>(self, optb: Option<U>) -> Option<U>

Returns None if the option is None, otherwise returns optb.

\n

Arguments passed to and are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use and_then, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);\n\nlet x: Option<u32> = None;\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), None);\n\nlet x = Some(2);\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), Some(\"foo\"));\n\nlet x: Option<u32> = None;\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);
\n
1.0.0 · source

pub fn and_then<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the\nwrapped value and returns the result.

\n

Some languages call this operation flatmap.

\n
Examples
\n
fn sq_then_to_string(x: u32) -> Option<String> {\n    x.checked_mul(x).map(|sq| sq.to_string())\n}\n\nassert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));\nassert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!\nassert_eq!(None.and_then(sq_then_to_string), None);
\n

Often used to chain fallible operations that may return None.

\n\n
let arr_2d = [[\"A0\", \"A1\"], [\"B0\", \"B1\"]];\n\nlet item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));\nassert_eq!(item_0_1, Some(&\"A1\"));\n\nlet item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));\nassert_eq!(item_2_0, None);
\n
1.27.0 · source

pub fn filter<P>(self, predicate: P) -> Option<T>
where\n P: FnOnce(&T) -> bool,

Returns None if the option is None, otherwise calls predicate\nwith the wrapped value and returns:

\n
    \n
  • Some(t) if predicate returns true (where t is the wrapped\nvalue), and
  • \n
  • None if predicate returns false.
  • \n
\n

This function works similar to Iterator::filter(). You can imagine\nthe Option<T> being an iterator over one or zero elements. filter()\nlets you decide which elements to keep.

\n
Examples
\n
fn is_even(n: &i32) -> bool {\n    n % 2 == 0\n}\n\nassert_eq!(None.filter(is_even), None);\nassert_eq!(Some(3).filter(is_even), None);\nassert_eq!(Some(4).filter(is_even), Some(4));
\n
1.0.0 · source

pub fn or(self, optb: Option<T>) -> Option<T>

Returns the option if it contains a value, otherwise returns optb.

\n

Arguments passed to or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y = None;\nassert_eq!(x.or(y), Some(2));\n\nlet x = None;\nlet y = Some(100);\nassert_eq!(x.or(y), Some(100));\n\nlet x = Some(2);\nlet y = Some(100);\nassert_eq!(x.or(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = None;\nassert_eq!(x.or(y), None);
\n
1.0.0 · source

pub fn or_else<F>(self, f: F) -> Option<T>
where\n F: FnOnce() -> Option<T>,

Returns the option if it contains a value, otherwise calls f and\nreturns the result.

\n
Examples
\n
fn nobody() -> Option<&'static str> { None }\nfn vikings() -> Option<&'static str> { Some(\"vikings\") }\n\nassert_eq!(Some(\"barbarians\").or_else(vikings), Some(\"barbarians\"));\nassert_eq!(None.or_else(vikings), Some(\"vikings\"));\nassert_eq!(None.or_else(nobody), None);
\n
1.37.0 · source

pub fn xor(self, optb: Option<T>) -> Option<T>

Returns Some if exactly one of self, optb is Some, otherwise returns None.

\n
Examples
\n
let x = Some(2);\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = Some(2);\nassert_eq!(x.xor(y), Some(2));\n\nlet x = Some(2);\nlet y = Some(2);\nassert_eq!(x.xor(y), None);\n\nlet x: Option<u32> = None;\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), None);
\n
1.53.0 · source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

\n

If the option already contains a value, the old value is dropped.

\n

See also Option::get_or_insert, which doesn’t update the value if\nthe option already contains Some.

\n
Example
\n
let mut opt = None;\nlet val = opt.insert(1);\nassert_eq!(*val, 1);\nassert_eq!(opt.unwrap(), 1);\nlet val = opt.insert(2);\nassert_eq!(*val, 2);\n*val = 3;\nassert_eq!(opt.unwrap(), 3);
\n
1.20.0 · source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n

See also Option::insert, which updates the value even if\nthe option already contains Some.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert(5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
source

pub fn get_or_insert_default(&mut self) -> &mut T
where\n T: Default,

🔬This is a nightly-only experimental API. (option_get_or_insert_default)

Inserts the default value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n
Examples
\n
#![feature(option_get_or_insert_default)]\n\nlet mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_default();\n    assert_eq!(y, &0);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.20.0 · source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where\n F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None,\nthen returns a mutable reference to the contained value.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_with(|| 5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.0.0 (const: unstable) · source

pub fn take(&mut self) -> Option<T>

Takes the value out of the option, leaving a None in its place.

\n
Examples
\n
let mut x = Some(2);\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, Some(2));\n\nlet mut x: Option<u32> = None;\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, None);
\n
source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where\n P: FnOnce(&mut T) -> bool,

🔬This is a nightly-only experimental API. (option_take_if)

Takes the value out of the option, but only if the predicate evaluates to\ntrue on a mutable reference to the value.

\n

In other words, replaces self with None if the predicate returns true.\nThis method operates similar to Option::take but conditional.

\n
Examples
\n
#![feature(option_take_if)]\n\nlet mut x = Some(42);\n\nlet prev = x.take_if(|v| if *v == 42 {\n    *v += 1;\n    false\n} else {\n    false\n});\nassert_eq!(x, Some(43));\nassert_eq!(prev, None);\n\nlet prev = x.take_if(|v| *v == 43);\nassert_eq!(x, None);\nassert_eq!(prev, Some(43));
\n
1.31.0 (const: unstable) · source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter,\nreturning the old value if present,\nleaving a Some in its place without deinitializing either one.

\n
Examples
\n
let mut x = Some(2);\nlet old = x.replace(5);\nassert_eq!(x, Some(5));\nassert_eq!(old, Some(2));\n\nlet mut x = None;\nlet old = x.replace(3);\nassert_eq!(x, Some(3));\nassert_eq!(old, None);
\n
1.46.0 · source

pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)>

Zips self with another Option.

\n

If self is Some(s) and other is Some(o), this method returns Some((s, o)).\nOtherwise, None is returned.

\n
Examples
\n
let x = Some(1);\nlet y = Some(\"hi\");\nlet z = None::<u8>;\n\nassert_eq!(x.zip(y), Some((1, \"hi\")));\nassert_eq!(x.zip(z), None);
\n
source

pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where\n F: FnOnce(T, U) -> R,

🔬This is a nightly-only experimental API. (option_zip)

Zips self and another Option with function f.

\n

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)).\nOtherwise, None is returned.

\n
Examples
\n
#![feature(option_zip)]\n\n#[derive(Debug, PartialEq)]\nstruct Point {\n    x: f64,\n    y: f64,\n}\n\nimpl Point {\n    fn new(x: f64, y: f64) -> Self {\n        Self { x, y }\n    }\n}\n\nlet x = Some(17.5);\nlet y = Some(42.7);\n\nassert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));\nassert_eq!(x.zip_with(None, Point::new), None);
\n
",0,"libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> PartialOrd for Option<T>
where\n T: PartialOrd,

source§

fn partial_cmp(&self, other: &Option<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <=\noperator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >=\noperator. Read more
","PartialOrd","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.37.0 · source§

impl<T, U> Product<Option<U>> for Option<T>
where\n T: Product<U>,

source§

fn product<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the product of all elements is returned.

\n
Examples
\n

This multiplies each number in a vector of strings,\nif a string could not be parsed the operation returns None:

\n\n
let nums = vec![\"5\", \"10\", \"1\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, Some(100));\nlet nums = vec![\"5\", \"10\", \"one\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, None);
\n
","Product>","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
source§

impl<T> FromResidual for Option<T>

source§

fn from_residual(residual: Option<Infallible>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

fn from_residual(_: Yeet<()>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual>","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
source§

impl<T> Try for Option<T>

§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

type Residual = Option<Infallible>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual\nas part of ? when short-circuiting. Read more
source§

fn from_output(output: <Option<T> as Try>::Output) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

fn branch(\n self\n) -> ControlFlow<<Option<T> as Try>::Residual, <Option<T> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value\n(because this returned ControlFlow::Continue)\nor propagate a value back to the caller\n(because this returned ControlFlow::Break). Read more
","Try","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Clone for Option<T>
where\n T: Clone,

source§

fn clone(&self) -> Option<T>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Option<T>)

Performs copy-assignment from source. Read more
","Clone","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<A, V> FromIterator<Option<A>> for Option<V>
where\n V: FromIterator<A>,

source§

fn from_iter<I>(iter: I) -> Option<V>
where\n I: IntoIterator<Item = Option<A>>,

Takes each element in the Iterator: if it is None,\nno further elements are taken, and the None is\nreturned. Should no None occur, a container of type\nV containing the values of each Option is returned.

\n
Examples
\n

Here is an example which increments every integer in a vector.\nWe use the checked variant of add that returns None when the\ncalculation would result in an overflow.

\n\n
let items = vec![0_u16, 1, 2];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_add(1))\n    .collect();\n\nassert_eq!(res, Some(vec![1, 2, 3]));
\n

As you can see, this will return the expected, valid items.

\n

Here is another example that tries to subtract one from another list\nof integers, this time checking for underflow:

\n\n
let items = vec![2_u16, 1, 0];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_sub(1))\n    .collect();\n\nassert_eq!(res, None);
\n

Since the last element is zero, it would underflow. Thus, the resulting\nvalue is None.

\n

Here is a variation on the previous example, showing that no\nfurther elements are taken from iter after the first None.

\n\n
let items = vec![3_u16, 2, 1, 10];\n\nlet mut shared = 0;\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| { shared += x; x.checked_sub(2) })\n    .collect();\n\nassert_eq!(res, None);\nassert_eq!(shared, 6);
\n

Since the third element caused an underflow, no further elements were taken,\nso the final value of shared is 6 (= 3 + 2 + 1), not 16.

\n
","FromIterator>","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> StructuralEq for Option<T>

","StructuralEq","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Eq for Option<T>
where\n T: Eq,

","Eq","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Hash for Option<T>
where\n T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where\n __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where\n H: Hasher,\n Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
","Hash","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Ord for Option<T>
where\n T: Ord,

source§

fn cmp(&self, other: &Option<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where\n Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
","Ord","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> PartialEq for Option<T>
where\n T: PartialEq,

source§

fn eq(&self, other: &Option<T>) -> bool

This method tests for self and other values to be equal, and is used\nby ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always\nsufficient, and should not be overridden without very good reason.
","PartialEq","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> IntoIterator for Option<T>

source§

fn into_iter(self) -> IntoIter<T>

Returns a consuming iterator over the possibly contained value.

\n
Examples
\n
let x = Some(\"string\");\nlet v: Vec<&str> = x.into_iter().collect();\nassert_eq!(v, [\"string\"]);\n\nlet x = None;\nlet v: Vec<&str> = x.into_iter().collect();\nassert!(v.is_empty());
\n
§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
","IntoIterator","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.37.0 · source§

impl<T, U> Sum<Option<U>> for Option<T>
where\n T: Sum<U>,

source§

fn sum<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the sum of all elements is returned.

\n
Examples
\n

This sums up the position of the character ‘a’ in a vector of strings,\nif a word did not have the character ‘a’ the operation returns None:

\n\n
let words = vec![\"have\", \"a\", \"great\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, Some(5));\nlet words = vec![\"have\", \"a\", \"good\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, None);
\n
","Sum>","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> StructuralPartialEq for Option<T>

","StructuralPartialEq","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Debug for Option<T>
where\n T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.12.0 · source§

impl<T> From<T> for Option<T>

source§

fn from(val: T) -> Option<T>

Moves val into a new Some.

\n
Examples
\n
let o: Option<u8> = Option::from(67);\n\nassert_eq!(Some(67), o);
\n
","From","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Copy for Option<T>
where\n T: Copy,

","Copy","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"],["
1.0.0 · source§

impl<T> Default for Option<T>

source§

fn default() -> Option<T>

Returns None.

\n
Examples
\n
let opt: Option<u32> = Option::default();\nassert!(opt.is_none());
\n
","Default","libgit2_sys::git_checkout_notify_cb","libgit2_sys::git_checkout_progress_cb","libgit2_sys::git_checkout_perfdata_cb","libgit2_sys::git_indexer_progress_cb","libgit2_sys::git_remote_ready_cb","libgit2_sys::git_transport_message_cb","libgit2_sys::git_cred_acquire_cb","libgit2_sys::git_transfer_progress_cb","libgit2_sys::git_packbuilder_progress","libgit2_sys::git_push_transfer_progress","libgit2_sys::git_transport_certificate_check_cb","libgit2_sys::git_push_negotiation","libgit2_sys::git_push_update_reference_cb","libgit2_sys::git_url_resolve_cb","libgit2_sys::git_repository_create_cb","libgit2_sys::git_remote_create_cb","libgit2_sys::git_treewalk_cb","libgit2_sys::git_treebuilder_filter_cb","libgit2_sys::git_revwalk_hide_cb","libgit2_sys::git_index_matched_path_cb","libgit2_sys::git_submodule_cb","libgit2_sys::git_cred_ssh_interactive_callback","libgit2_sys::git_cred_sign_callback","libgit2_sys::git_tag_foreach_cb","libgit2_sys::git_diff_file_cb","libgit2_sys::git_diff_hunk_cb","libgit2_sys::git_diff_line_cb","libgit2_sys::git_diff_binary_cb","libgit2_sys::git_diff_notify_cb","libgit2_sys::git_diff_progress_cb","libgit2_sys::git_transport_cb","libgit2_sys::git_smart_subtransport_cb","libgit2_sys::git_stash_apply_progress_cb","libgit2_sys::git_stash_cb","libgit2_sys::git_packbuilder_foreach_cb","libgit2_sys::git_odb_foreach_cb","libgit2_sys::git_commit_signing_cb","libgit2_sys::git_commit_create_cb","libgit2_sys::git_apply_delta_cb","libgit2_sys::git_apply_hunk_cb","libgit2_sys::git_repository_mergehead_foreach_cb","libgit2_sys::git_repository_fetchhead_foreach_cb","libgit2_sys::git_trace_cb"]], "llvm_sys":[["
source§

impl<T> Option<T>

1.0.0 (const: 1.48.0) · source

pub const fn is_some(&self) -> bool

Returns true if the option is a Some value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some(), true);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some(), false);
\n
1.70.0 · source

pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a Some and the value inside of it matches a predicate.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some_and(|x| x > 1), true);\n\nlet x: Option<u32> = Some(0);\nassert_eq!(x.is_some_and(|x| x > 1), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some_and(|x| x > 1), false);
\n
1.0.0 (const: 1.48.0) · source

pub const fn is_none(&self) -> bool

Returns true if the option is a None value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_none(), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_none(), true);
\n
1.0.0 (const: 1.48.0) · source

pub const fn as_ref(&self) -> Option<&T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Calculates the length of an Option<String> as an Option<usize>\nwithout moving the String. The map method takes the self argument by value,\nconsuming the original, so this technique uses as_ref to first take an Option to a\nreference to the value inside the original.

\n\n
let text: Option<String> = Some(\"Hello, world!\".to_string());\n// First, cast `Option<String>` to `Option<&String>` with `as_ref`,\n// then consume *that* with `map`, leaving `text` on the stack.\nlet text_length: Option<usize> = text.as_ref().map(|s| s.len());\nprintln!(\"still can print text: {text:?}\");
\n
1.0.0 (const: unstable) · source

pub fn as_mut(&mut self) -> Option<&mut T>

Converts from &mut Option<T> to Option<&mut T>.

\n
Examples
\n
let mut x = Some(2);\nmatch x.as_mut() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));
\n
1.33.0 (const: unstable) · source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

\n
1.33.0 (const: unstable) · source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

\n
1.75.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an\nempty slice is returned. This can be useful to have a single type of\niterator over an Option or slice.

\n

Note: Should you have an Option<&T> and wish to get a slice of T,\nyou can unpack it via opt.map_or(&[], std::slice::from_ref).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_slice(), None.as_slice()],\n    [&[1234][..], &[][..]],\n);
\n

The inverse of this function is (discounting\nborrowing) [_]::first:

\n\n
for i in [Some(1234_u16), None] {\n    assert_eq!(i.as_ref(), i.as_slice().first());\n}
\n
1.75.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is\nNone, an empty slice is returned. This can be useful to have a\nsingle type of iterator over an Option or slice.

\n

Note: Should you have an Option<&mut T> instead of a\n&mut Option<T>, which this method takes, you can obtain a mutable\nslice via opt.map_or(&mut [], std::slice::from_mut).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_mut_slice(), None.as_mut_slice()],\n    [&mut [1234][..], &mut [][..]],\n);
\n

The result is a mutable slice of zero or one items that points into\nour original Option:

\n\n
let mut x = Some(1234);\nx.as_mut_slice()[0] += 1;\nassert_eq!(x, Some(1235));
\n

The inverse of this method (discounting borrowing)\nis [_]::first_mut:

\n\n
assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
\n
1.0.0 (const: unstable) · source

pub fn expect(self, msg: &str) -> T

Returns the contained Some value, consuming the self value.

\n
Panics
\n

Panics if the value is a None with a custom panic message provided by\nmsg.

\n
Examples
\n
let x = Some(\"value\");\nassert_eq!(x.expect(\"fruits are healthy\"), \"value\");
\n\n
let x: Option<&str> = None;\nx.expect(\"fruits are healthy\"); // panics with `fruits are healthy`
\n
Recommended Message Style
\n

We recommend that expect messages are used to describe the reason you\nexpect the Option should be Some.

\n\n
let item = slice.get(0)\n    .expect(\"slice should not be empty\");
\n

Hint: If you’re having trouble remembering how to phrase expect\nerror messages remember to focus on the word “should” as in “env\nvariable should be set by blah” or “the given binary should be available\nand executable by the current user”.

\n

For more detail on expect message styles and the reasoning behind our\nrecommendation please refer to the section on “Common Message\nStyles” in the std::error module docs.

\n
1.0.0 (const: unstable) · source

pub fn unwrap(self) -> T

Returns the contained Some value, consuming the self value.

\n

Because this function may panic, its use is generally discouraged.\nInstead, prefer to use pattern matching and handle the None\ncase explicitly, or call unwrap_or, unwrap_or_else, or\nunwrap_or_default.

\n
Panics
\n

Panics if the self value equals None.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(x.unwrap(), \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(x.unwrap(), \"air\"); // fails
\n
1.0.0 · source

pub fn unwrap_or(self, default: T) -> T

Returns the contained Some value or a provided default.

\n

Arguments passed to unwrap_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use unwrap_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
assert_eq!(Some(\"car\").unwrap_or(\"bike\"), \"car\");\nassert_eq!(None.unwrap_or(\"bike\"), \"bike\");
\n
1.0.0 · source

pub fn unwrap_or_else<F>(self, f: F) -> T
where\n F: FnOnce() -> T,

Returns the contained Some value or computes it from a closure.

\n
Examples
\n
let k = 10;\nassert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);\nassert_eq!(None.unwrap_or_else(|| 2 * k), 20);
\n
1.0.0 · source

pub fn unwrap_or_default(self) -> T
where\n T: Default,

Returns the contained Some value or a default.

\n

Consumes the self argument then, if Some, returns the contained\nvalue, otherwise if None, returns the default value for that\ntype.

\n
Examples
\n
let x: Option<u32> = None;\nlet y: Option<u32> = Some(12);\n\nassert_eq!(x.unwrap_or_default(), 0);\nassert_eq!(y.unwrap_or_default(), 12);
\n
1.58.0 (const: unstable) · source

pub unsafe fn unwrap_unchecked(self) -> T

Returns the contained Some value, consuming the self value,\nwithout checking that the value is not None.

\n
Safety
\n

Calling this method on None is undefined behavior.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\"); // Undefined behavior!
\n
1.0.0 · source

pub fn map<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> U,

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

\n
Examples
\n

Calculates the length of an Option<String> as an\nOption<usize>, consuming the original:

\n\n
let maybe_some_string = Some(String::from(\"Hello, World!\"));\n// `Option::map` takes self *by value*, consuming `maybe_some_string`\nlet maybe_some_len = maybe_some_string.map(|s| s.len());\nassert_eq!(maybe_some_len, Some(13));\n\nlet x: Option<&str> = None;\nassert_eq!(x.map(|s| s.len()), None);
\n
1.76.0 · source

pub fn inspect<F>(self, f: F) -> Option<T>
where\n F: FnOnce(&T),

Calls the provided closure with a reference to the contained value (if Some).

\n
Examples
\n
let v = vec![1, 2, 3, 4, 5];\n\n// prints \"got: 4\"\nlet x: Option<&usize> = v.get(3).inspect(|x| println!(\"got: {x}\"));\n\n// prints nothing\nlet x: Option<&usize> = v.get(5).inspect(|x| println!(\"got: {x}\"));
\n
1.0.0 · source

pub fn map_or<U, F>(self, default: U, f: F) -> U
where\n F: FnOnce(T) -> U,

Returns the provided default result (if none),\nor applies a function to the contained value (if any).

\n

Arguments passed to map_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use map_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.map_or(42, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or(42, |v| v.len()), 42);
\n
1.0.0 · source

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where\n D: FnOnce() -> U,\n F: FnOnce(T) -> U,

Computes a default function result (if none), or\napplies a different function to the contained value (if any).

\n
Basic examples
\n
let k = 21;\n\nlet x = Some(\"foo\");\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
\n
Handling a Result-based fallback
\n

A somewhat common occurrence when dealing with optional values\nin combination with Result<T, E> is the case where one wants to invoke\na fallible fallback if the option is not present. This example\nparses a command line argument (if present), or the contents of a file to\nan integer. However, unlike accessing the command line argument, reading\nthe file is fallible, so it must be wrapped with Ok.

\n\n
let v: u64 = std::env::args()\n   .nth(1)\n   .map_or_else(|| std::fs::read_to_string(\"/etc/someconfig.conf\"), Ok)?\n   .parse()?;
\n
1.0.0 · source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err).

\n

Arguments passed to ok_or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use ok_or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or(0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or(0), Err(0));
\n
1.0.0 · source

pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where\n F: FnOnce() -> E,

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err()).

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or_else(|| 0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or_else(|| 0), Err(0));
\n
1.40.0 · source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where\n T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

\n

Leaves the original Option in-place, creating a new one with a reference\nto the original one, additionally coercing the contents via Deref.

\n
Examples
\n
let x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref(), Some(\"hey\"));\n\nlet x: Option<String> = None;\nassert_eq!(x.as_deref(), None);
\n
1.40.0 · source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where\n T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

\n

Leaves the original Option in-place, creating a new one containing a mutable reference to\nthe inner type’s Deref::Target type.

\n
Examples
\n
let mut x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref_mut().map(|x| {\n    x.make_ascii_uppercase();\n    x\n}), Some(\"HEY\".to_owned().as_mut_str()));
\n
1.0.0 (const: unstable) · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

\n
Examples
\n
let x = Some(4);\nassert_eq!(x.iter().next(), Some(&4));\n\nlet x: Option<u32> = None;\nassert_eq!(x.iter().next(), None);
\n
1.0.0 · source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

\n
Examples
\n
let mut x = Some(4);\nmatch x.iter_mut().next() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));\n\nlet mut x: Option<u32> = None;\nassert_eq!(x.iter_mut().next(), None);
\n
1.0.0 · source

pub fn and<U>(self, optb: Option<U>) -> Option<U>

Returns None if the option is None, otherwise returns optb.

\n

Arguments passed to and are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use and_then, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);\n\nlet x: Option<u32> = None;\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), None);\n\nlet x = Some(2);\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), Some(\"foo\"));\n\nlet x: Option<u32> = None;\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);
\n
1.0.0 · source

pub fn and_then<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the\nwrapped value and returns the result.

\n

Some languages call this operation flatmap.

\n
Examples
\n
fn sq_then_to_string(x: u32) -> Option<String> {\n    x.checked_mul(x).map(|sq| sq.to_string())\n}\n\nassert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));\nassert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!\nassert_eq!(None.and_then(sq_then_to_string), None);
\n

Often used to chain fallible operations that may return None.

\n\n
let arr_2d = [[\"A0\", \"A1\"], [\"B0\", \"B1\"]];\n\nlet item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));\nassert_eq!(item_0_1, Some(&\"A1\"));\n\nlet item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));\nassert_eq!(item_2_0, None);
\n
1.27.0 · source

pub fn filter<P>(self, predicate: P) -> Option<T>
where\n P: FnOnce(&T) -> bool,

Returns None if the option is None, otherwise calls predicate\nwith the wrapped value and returns:

\n
    \n
  • Some(t) if predicate returns true (where t is the wrapped\nvalue), and
  • \n
  • None if predicate returns false.
  • \n
\n

This function works similar to Iterator::filter(). You can imagine\nthe Option<T> being an iterator over one or zero elements. filter()\nlets you decide which elements to keep.

\n
Examples
\n
fn is_even(n: &i32) -> bool {\n    n % 2 == 0\n}\n\nassert_eq!(None.filter(is_even), None);\nassert_eq!(Some(3).filter(is_even), None);\nassert_eq!(Some(4).filter(is_even), Some(4));
\n
1.0.0 · source

pub fn or(self, optb: Option<T>) -> Option<T>

Returns the option if it contains a value, otherwise returns optb.

\n

Arguments passed to or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y = None;\nassert_eq!(x.or(y), Some(2));\n\nlet x = None;\nlet y = Some(100);\nassert_eq!(x.or(y), Some(100));\n\nlet x = Some(2);\nlet y = Some(100);\nassert_eq!(x.or(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = None;\nassert_eq!(x.or(y), None);
\n
1.0.0 · source

pub fn or_else<F>(self, f: F) -> Option<T>
where\n F: FnOnce() -> Option<T>,

Returns the option if it contains a value, otherwise calls f and\nreturns the result.

\n
Examples
\n
fn nobody() -> Option<&'static str> { None }\nfn vikings() -> Option<&'static str> { Some(\"vikings\") }\n\nassert_eq!(Some(\"barbarians\").or_else(vikings), Some(\"barbarians\"));\nassert_eq!(None.or_else(vikings), Some(\"vikings\"));\nassert_eq!(None.or_else(nobody), None);
\n
1.37.0 · source

pub fn xor(self, optb: Option<T>) -> Option<T>

Returns Some if exactly one of self, optb is Some, otherwise returns None.

\n
Examples
\n
let x = Some(2);\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = Some(2);\nassert_eq!(x.xor(y), Some(2));\n\nlet x = Some(2);\nlet y = Some(2);\nassert_eq!(x.xor(y), None);\n\nlet x: Option<u32> = None;\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), None);
\n
1.53.0 · source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

\n

If the option already contains a value, the old value is dropped.

\n

See also Option::get_or_insert, which doesn’t update the value if\nthe option already contains Some.

\n
Example
\n
let mut opt = None;\nlet val = opt.insert(1);\nassert_eq!(*val, 1);\nassert_eq!(opt.unwrap(), 1);\nlet val = opt.insert(2);\nassert_eq!(*val, 2);\n*val = 3;\nassert_eq!(opt.unwrap(), 3);
\n
1.20.0 · source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n

See also Option::insert, which updates the value even if\nthe option already contains Some.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert(5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
source

pub fn get_or_insert_default(&mut self) -> &mut T
where\n T: Default,

🔬This is a nightly-only experimental API. (option_get_or_insert_default)

Inserts the default value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n
Examples
\n
#![feature(option_get_or_insert_default)]\n\nlet mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_default();\n    assert_eq!(y, &0);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.20.0 · source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where\n F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None,\nthen returns a mutable reference to the contained value.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_with(|| 5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.0.0 (const: unstable) · source

pub fn take(&mut self) -> Option<T>

Takes the value out of the option, leaving a None in its place.

\n
Examples
\n
let mut x = Some(2);\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, Some(2));\n\nlet mut x: Option<u32> = None;\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, None);
\n
source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where\n P: FnOnce(&mut T) -> bool,

🔬This is a nightly-only experimental API. (option_take_if)

Takes the value out of the option, but only if the predicate evaluates to\ntrue on a mutable reference to the value.

\n

In other words, replaces self with None if the predicate returns true.\nThis method operates similar to Option::take but conditional.

\n
Examples
\n
#![feature(option_take_if)]\n\nlet mut x = Some(42);\n\nlet prev = x.take_if(|v| if *v == 42 {\n    *v += 1;\n    false\n} else {\n    false\n});\nassert_eq!(x, Some(43));\nassert_eq!(prev, None);\n\nlet prev = x.take_if(|v| *v == 43);\nassert_eq!(x, None);\nassert_eq!(prev, Some(43));
\n
1.31.0 (const: unstable) · source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter,\nreturning the old value if present,\nleaving a Some in its place without deinitializing either one.

\n
Examples
\n
let mut x = Some(2);\nlet old = x.replace(5);\nassert_eq!(x, Some(5));\nassert_eq!(old, Some(2));\n\nlet mut x = None;\nlet old = x.replace(3);\nassert_eq!(x, Some(3));\nassert_eq!(old, None);
\n
1.46.0 · source

pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)>

Zips self with another Option.

\n

If self is Some(s) and other is Some(o), this method returns Some((s, o)).\nOtherwise, None is returned.

\n
Examples
\n
let x = Some(1);\nlet y = Some(\"hi\");\nlet z = None::<u8>;\n\nassert_eq!(x.zip(y), Some((1, \"hi\")));\nassert_eq!(x.zip(z), None);
\n
source

pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where\n F: FnOnce(T, U) -> R,

🔬This is a nightly-only experimental API. (option_zip)

Zips self and another Option with function f.

\n

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)).\nOtherwise, None is returned.

\n
Examples
\n
#![feature(option_zip)]\n\n#[derive(Debug, PartialEq)]\nstruct Point {\n    x: f64,\n    y: f64,\n}\n\nimpl Point {\n    fn new(x: f64, y: f64) -> Self {\n        Self { x, y }\n    }\n}\n\nlet x = Some(17.5);\nlet y = Some(42.7);\n\nassert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));\nassert_eq!(x.zip_with(None, Point::new), None);
\n
",0,"llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> PartialOrd for Option<T>
where\n T: PartialOrd,

source§

fn partial_cmp(&self, other: &Option<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <=\noperator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >=\noperator. Read more
","PartialOrd","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.37.0 · source§

impl<T, U> Product<Option<U>> for Option<T>
where\n T: Product<U>,

source§

fn product<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the product of all elements is returned.

\n
Examples
\n

This multiplies each number in a vector of strings,\nif a string could not be parsed the operation returns None:

\n\n
let nums = vec![\"5\", \"10\", \"1\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, Some(100));\nlet nums = vec![\"5\", \"10\", \"one\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, None);
\n
","Product>","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
source§

impl<T> FromResidual for Option<T>

source§

fn from_residual(residual: Option<Infallible>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

fn from_residual(_: Yeet<()>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual>","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
source§

impl<T> Try for Option<T>

§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

type Residual = Option<Infallible>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual\nas part of ? when short-circuiting. Read more
source§

fn from_output(output: <Option<T> as Try>::Output) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

fn branch(\n self\n) -> ControlFlow<<Option<T> as Try>::Residual, <Option<T> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value\n(because this returned ControlFlow::Continue)\nor propagate a value back to the caller\n(because this returned ControlFlow::Break). Read more
","Try","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Clone for Option<T>
where\n T: Clone,

source§

fn clone(&self) -> Option<T>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Option<T>)

Performs copy-assignment from source. Read more
","Clone","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<A, V> FromIterator<Option<A>> for Option<V>
where\n V: FromIterator<A>,

source§

fn from_iter<I>(iter: I) -> Option<V>
where\n I: IntoIterator<Item = Option<A>>,

Takes each element in the Iterator: if it is None,\nno further elements are taken, and the None is\nreturned. Should no None occur, a container of type\nV containing the values of each Option is returned.

\n
Examples
\n

Here is an example which increments every integer in a vector.\nWe use the checked variant of add that returns None when the\ncalculation would result in an overflow.

\n\n
let items = vec![0_u16, 1, 2];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_add(1))\n    .collect();\n\nassert_eq!(res, Some(vec![1, 2, 3]));
\n

As you can see, this will return the expected, valid items.

\n

Here is another example that tries to subtract one from another list\nof integers, this time checking for underflow:

\n\n
let items = vec![2_u16, 1, 0];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_sub(1))\n    .collect();\n\nassert_eq!(res, None);
\n

Since the last element is zero, it would underflow. Thus, the resulting\nvalue is None.

\n

Here is a variation on the previous example, showing that no\nfurther elements are taken from iter after the first None.

\n\n
let items = vec![3_u16, 2, 1, 10];\n\nlet mut shared = 0;\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| { shared += x; x.checked_sub(2) })\n    .collect();\n\nassert_eq!(res, None);\nassert_eq!(shared, 6);
\n

Since the third element caused an underflow, no further elements were taken,\nso the final value of shared is 6 (= 3 + 2 + 1), not 16.

\n
","FromIterator>","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> StructuralEq for Option<T>

","StructuralEq","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Eq for Option<T>
where\n T: Eq,

","Eq","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Hash for Option<T>
where\n T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where\n __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where\n H: Hasher,\n Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
","Hash","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Ord for Option<T>
where\n T: Ord,

source§

fn cmp(&self, other: &Option<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where\n Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
","Ord","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> PartialEq for Option<T>
where\n T: PartialEq,

source§

fn eq(&self, other: &Option<T>) -> bool

This method tests for self and other values to be equal, and is used\nby ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always\nsufficient, and should not be overridden without very good reason.
","PartialEq","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> IntoIterator for Option<T>

source§

fn into_iter(self) -> IntoIter<T>

Returns a consuming iterator over the possibly contained value.

\n
Examples
\n
let x = Some(\"string\");\nlet v: Vec<&str> = x.into_iter().collect();\nassert_eq!(v, [\"string\"]);\n\nlet x = None;\nlet v: Vec<&str> = x.into_iter().collect();\nassert!(v.is_empty());
\n
§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
","IntoIterator","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.37.0 · source§

impl<T, U> Sum<Option<U>> for Option<T>
where\n T: Sum<U>,

source§

fn sum<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the sum of all elements is returned.

\n
Examples
\n

This sums up the position of the character ‘a’ in a vector of strings,\nif a word did not have the character ‘a’ the operation returns None:

\n\n
let words = vec![\"have\", \"a\", \"great\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, Some(5));\nlet words = vec![\"have\", \"a\", \"good\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, None);
\n
","Sum>","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> StructuralPartialEq for Option<T>

","StructuralPartialEq","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Debug for Option<T>
where\n T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.12.0 · source§

impl<T> From<T> for Option<T>

source§

fn from(val: T) -> Option<T>

Moves val into a new Some.

\n
Examples
\n
let o: Option<u8> = Option::from(67);\n\nassert_eq!(Some(67), o);
\n
","From","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Copy for Option<T>
where\n T: Copy,

","Copy","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"],["
1.0.0 · source§

impl<T> Default for Option<T>

source§

fn default() -> Option<T>

Returns None.

\n
Examples
\n
let opt: Option<u32> = Option::default();\nassert!(opt.is_none());
\n
","Default","llvm_sys::disassembler::LLVMOpInfoCallback","llvm_sys::disassembler::LLVMSymbolLookupCallback","llvm_sys::error_handling::LLVMFatalErrorHandler","llvm_sys::execution_engine::LLVMMemoryManagerDestroyCallback","llvm_sys::lto::lto_diagnostic_handler_t","llvm_sys::orc2::LLVMOrcSymbolPredicate","llvm_sys::LLVMDiagnosticHandler","llvm_sys::LLVMYieldCallback"]], "openssl_sys":[["
source§

impl<T> Option<T>

1.0.0 (const: 1.48.0) · source

pub const fn is_some(&self) -> bool

Returns true if the option is a Some value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some(), true);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some(), false);
\n
1.70.0 · source

pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a Some and the value inside of it matches a predicate.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some_and(|x| x > 1), true);\n\nlet x: Option<u32> = Some(0);\nassert_eq!(x.is_some_and(|x| x > 1), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some_and(|x| x > 1), false);
\n
1.0.0 (const: 1.48.0) · source

pub const fn is_none(&self) -> bool

Returns true if the option is a None value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_none(), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_none(), true);
\n
1.0.0 (const: 1.48.0) · source

pub const fn as_ref(&self) -> Option<&T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Calculates the length of an Option<String> as an Option<usize>\nwithout moving the String. The map method takes the self argument by value,\nconsuming the original, so this technique uses as_ref to first take an Option to a\nreference to the value inside the original.

\n\n
let text: Option<String> = Some(\"Hello, world!\".to_string());\n// First, cast `Option<String>` to `Option<&String>` with `as_ref`,\n// then consume *that* with `map`, leaving `text` on the stack.\nlet text_length: Option<usize> = text.as_ref().map(|s| s.len());\nprintln!(\"still can print text: {text:?}\");
\n
1.0.0 (const: unstable) · source

pub fn as_mut(&mut self) -> Option<&mut T>

Converts from &mut Option<T> to Option<&mut T>.

\n
Examples
\n
let mut x = Some(2);\nmatch x.as_mut() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));
\n
1.33.0 (const: unstable) · source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

\n
1.33.0 (const: unstable) · source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

\n
1.75.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an\nempty slice is returned. This can be useful to have a single type of\niterator over an Option or slice.

\n

Note: Should you have an Option<&T> and wish to get a slice of T,\nyou can unpack it via opt.map_or(&[], std::slice::from_ref).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_slice(), None.as_slice()],\n    [&[1234][..], &[][..]],\n);
\n

The inverse of this function is (discounting\nborrowing) [_]::first:

\n\n
for i in [Some(1234_u16), None] {\n    assert_eq!(i.as_ref(), i.as_slice().first());\n}
\n
1.75.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is\nNone, an empty slice is returned. This can be useful to have a\nsingle type of iterator over an Option or slice.

\n

Note: Should you have an Option<&mut T> instead of a\n&mut Option<T>, which this method takes, you can obtain a mutable\nslice via opt.map_or(&mut [], std::slice::from_mut).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_mut_slice(), None.as_mut_slice()],\n    [&mut [1234][..], &mut [][..]],\n);
\n

The result is a mutable slice of zero or one items that points into\nour original Option:

\n\n
let mut x = Some(1234);\nx.as_mut_slice()[0] += 1;\nassert_eq!(x, Some(1235));
\n

The inverse of this method (discounting borrowing)\nis [_]::first_mut:

\n\n
assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
\n
1.0.0 (const: unstable) · source

pub fn expect(self, msg: &str) -> T

Returns the contained Some value, consuming the self value.

\n
Panics
\n

Panics if the value is a None with a custom panic message provided by\nmsg.

\n
Examples
\n
let x = Some(\"value\");\nassert_eq!(x.expect(\"fruits are healthy\"), \"value\");
\n\n
let x: Option<&str> = None;\nx.expect(\"fruits are healthy\"); // panics with `fruits are healthy`
\n
Recommended Message Style
\n

We recommend that expect messages are used to describe the reason you\nexpect the Option should be Some.

\n\n
let item = slice.get(0)\n    .expect(\"slice should not be empty\");
\n

Hint: If you’re having trouble remembering how to phrase expect\nerror messages remember to focus on the word “should” as in “env\nvariable should be set by blah” or “the given binary should be available\nand executable by the current user”.

\n

For more detail on expect message styles and the reasoning behind our\nrecommendation please refer to the section on “Common Message\nStyles” in the std::error module docs.

\n
1.0.0 (const: unstable) · source

pub fn unwrap(self) -> T

Returns the contained Some value, consuming the self value.

\n

Because this function may panic, its use is generally discouraged.\nInstead, prefer to use pattern matching and handle the None\ncase explicitly, or call unwrap_or, unwrap_or_else, or\nunwrap_or_default.

\n
Panics
\n

Panics if the self value equals None.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(x.unwrap(), \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(x.unwrap(), \"air\"); // fails
\n
1.0.0 · source

pub fn unwrap_or(self, default: T) -> T

Returns the contained Some value or a provided default.

\n

Arguments passed to unwrap_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use unwrap_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
assert_eq!(Some(\"car\").unwrap_or(\"bike\"), \"car\");\nassert_eq!(None.unwrap_or(\"bike\"), \"bike\");
\n
1.0.0 · source

pub fn unwrap_or_else<F>(self, f: F) -> T
where\n F: FnOnce() -> T,

Returns the contained Some value or computes it from a closure.

\n
Examples
\n
let k = 10;\nassert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);\nassert_eq!(None.unwrap_or_else(|| 2 * k), 20);
\n
1.0.0 · source

pub fn unwrap_or_default(self) -> T
where\n T: Default,

Returns the contained Some value or a default.

\n

Consumes the self argument then, if Some, returns the contained\nvalue, otherwise if None, returns the default value for that\ntype.

\n
Examples
\n
let x: Option<u32> = None;\nlet y: Option<u32> = Some(12);\n\nassert_eq!(x.unwrap_or_default(), 0);\nassert_eq!(y.unwrap_or_default(), 12);
\n
1.58.0 (const: unstable) · source

pub unsafe fn unwrap_unchecked(self) -> T

Returns the contained Some value, consuming the self value,\nwithout checking that the value is not None.

\n
Safety
\n

Calling this method on None is undefined behavior.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\"); // Undefined behavior!
\n
1.0.0 · source

pub fn map<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> U,

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

\n
Examples
\n

Calculates the length of an Option<String> as an\nOption<usize>, consuming the original:

\n\n
let maybe_some_string = Some(String::from(\"Hello, World!\"));\n// `Option::map` takes self *by value*, consuming `maybe_some_string`\nlet maybe_some_len = maybe_some_string.map(|s| s.len());\nassert_eq!(maybe_some_len, Some(13));\n\nlet x: Option<&str> = None;\nassert_eq!(x.map(|s| s.len()), None);
\n
1.76.0 · source

pub fn inspect<F>(self, f: F) -> Option<T>
where\n F: FnOnce(&T),

Calls the provided closure with a reference to the contained value (if Some).

\n
Examples
\n
let v = vec![1, 2, 3, 4, 5];\n\n// prints \"got: 4\"\nlet x: Option<&usize> = v.get(3).inspect(|x| println!(\"got: {x}\"));\n\n// prints nothing\nlet x: Option<&usize> = v.get(5).inspect(|x| println!(\"got: {x}\"));
\n
1.0.0 · source

pub fn map_or<U, F>(self, default: U, f: F) -> U
where\n F: FnOnce(T) -> U,

Returns the provided default result (if none),\nor applies a function to the contained value (if any).

\n

Arguments passed to map_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use map_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.map_or(42, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or(42, |v| v.len()), 42);
\n
1.0.0 · source

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where\n D: FnOnce() -> U,\n F: FnOnce(T) -> U,

Computes a default function result (if none), or\napplies a different function to the contained value (if any).

\n
Basic examples
\n
let k = 21;\n\nlet x = Some(\"foo\");\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
\n
Handling a Result-based fallback
\n

A somewhat common occurrence when dealing with optional values\nin combination with Result<T, E> is the case where one wants to invoke\na fallible fallback if the option is not present. This example\nparses a command line argument (if present), or the contents of a file to\nan integer. However, unlike accessing the command line argument, reading\nthe file is fallible, so it must be wrapped with Ok.

\n\n
let v: u64 = std::env::args()\n   .nth(1)\n   .map_or_else(|| std::fs::read_to_string(\"/etc/someconfig.conf\"), Ok)?\n   .parse()?;
\n
1.0.0 · source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err).

\n

Arguments passed to ok_or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use ok_or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or(0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or(0), Err(0));
\n
1.0.0 · source

pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where\n F: FnOnce() -> E,

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err()).

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or_else(|| 0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or_else(|| 0), Err(0));
\n
1.40.0 · source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where\n T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

\n

Leaves the original Option in-place, creating a new one with a reference\nto the original one, additionally coercing the contents via Deref.

\n
Examples
\n
let x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref(), Some(\"hey\"));\n\nlet x: Option<String> = None;\nassert_eq!(x.as_deref(), None);
\n
1.40.0 · source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where\n T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

\n

Leaves the original Option in-place, creating a new one containing a mutable reference to\nthe inner type’s Deref::Target type.

\n
Examples
\n
let mut x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref_mut().map(|x| {\n    x.make_ascii_uppercase();\n    x\n}), Some(\"HEY\".to_owned().as_mut_str()));
\n
1.0.0 (const: unstable) · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

\n
Examples
\n
let x = Some(4);\nassert_eq!(x.iter().next(), Some(&4));\n\nlet x: Option<u32> = None;\nassert_eq!(x.iter().next(), None);
\n
1.0.0 · source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

\n
Examples
\n
let mut x = Some(4);\nmatch x.iter_mut().next() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));\n\nlet mut x: Option<u32> = None;\nassert_eq!(x.iter_mut().next(), None);
\n
1.0.0 · source

pub fn and<U>(self, optb: Option<U>) -> Option<U>

Returns None if the option is None, otherwise returns optb.

\n

Arguments passed to and are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use and_then, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);\n\nlet x: Option<u32> = None;\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), None);\n\nlet x = Some(2);\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), Some(\"foo\"));\n\nlet x: Option<u32> = None;\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);
\n
1.0.0 · source

pub fn and_then<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the\nwrapped value and returns the result.

\n

Some languages call this operation flatmap.

\n
Examples
\n
fn sq_then_to_string(x: u32) -> Option<String> {\n    x.checked_mul(x).map(|sq| sq.to_string())\n}\n\nassert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));\nassert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!\nassert_eq!(None.and_then(sq_then_to_string), None);
\n

Often used to chain fallible operations that may return None.

\n\n
let arr_2d = [[\"A0\", \"A1\"], [\"B0\", \"B1\"]];\n\nlet item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));\nassert_eq!(item_0_1, Some(&\"A1\"));\n\nlet item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));\nassert_eq!(item_2_0, None);
\n
1.27.0 · source

pub fn filter<P>(self, predicate: P) -> Option<T>
where\n P: FnOnce(&T) -> bool,

Returns None if the option is None, otherwise calls predicate\nwith the wrapped value and returns:

\n
    \n
  • Some(t) if predicate returns true (where t is the wrapped\nvalue), and
  • \n
  • None if predicate returns false.
  • \n
\n

This function works similar to Iterator::filter(). You can imagine\nthe Option<T> being an iterator over one or zero elements. filter()\nlets you decide which elements to keep.

\n
Examples
\n
fn is_even(n: &i32) -> bool {\n    n % 2 == 0\n}\n\nassert_eq!(None.filter(is_even), None);\nassert_eq!(Some(3).filter(is_even), None);\nassert_eq!(Some(4).filter(is_even), Some(4));
\n
1.0.0 · source

pub fn or(self, optb: Option<T>) -> Option<T>

Returns the option if it contains a value, otherwise returns optb.

\n

Arguments passed to or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y = None;\nassert_eq!(x.or(y), Some(2));\n\nlet x = None;\nlet y = Some(100);\nassert_eq!(x.or(y), Some(100));\n\nlet x = Some(2);\nlet y = Some(100);\nassert_eq!(x.or(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = None;\nassert_eq!(x.or(y), None);
\n
1.0.0 · source

pub fn or_else<F>(self, f: F) -> Option<T>
where\n F: FnOnce() -> Option<T>,

Returns the option if it contains a value, otherwise calls f and\nreturns the result.

\n
Examples
\n
fn nobody() -> Option<&'static str> { None }\nfn vikings() -> Option<&'static str> { Some(\"vikings\") }\n\nassert_eq!(Some(\"barbarians\").or_else(vikings), Some(\"barbarians\"));\nassert_eq!(None.or_else(vikings), Some(\"vikings\"));\nassert_eq!(None.or_else(nobody), None);
\n
1.37.0 · source

pub fn xor(self, optb: Option<T>) -> Option<T>

Returns Some if exactly one of self, optb is Some, otherwise returns None.

\n
Examples
\n
let x = Some(2);\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = Some(2);\nassert_eq!(x.xor(y), Some(2));\n\nlet x = Some(2);\nlet y = Some(2);\nassert_eq!(x.xor(y), None);\n\nlet x: Option<u32> = None;\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), None);
\n
1.53.0 · source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

\n

If the option already contains a value, the old value is dropped.

\n

See also Option::get_or_insert, which doesn’t update the value if\nthe option already contains Some.

\n
Example
\n
let mut opt = None;\nlet val = opt.insert(1);\nassert_eq!(*val, 1);\nassert_eq!(opt.unwrap(), 1);\nlet val = opt.insert(2);\nassert_eq!(*val, 2);\n*val = 3;\nassert_eq!(opt.unwrap(), 3);
\n
1.20.0 · source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n

See also Option::insert, which updates the value even if\nthe option already contains Some.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert(5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
source

pub fn get_or_insert_default(&mut self) -> &mut T
where\n T: Default,

🔬This is a nightly-only experimental API. (option_get_or_insert_default)

Inserts the default value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n
Examples
\n
#![feature(option_get_or_insert_default)]\n\nlet mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_default();\n    assert_eq!(y, &0);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.20.0 · source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where\n F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None,\nthen returns a mutable reference to the contained value.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_with(|| 5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.0.0 (const: unstable) · source

pub fn take(&mut self) -> Option<T>

Takes the value out of the option, leaving a None in its place.

\n
Examples
\n
let mut x = Some(2);\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, Some(2));\n\nlet mut x: Option<u32> = None;\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, None);
\n
source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where\n P: FnOnce(&mut T) -> bool,

🔬This is a nightly-only experimental API. (option_take_if)

Takes the value out of the option, but only if the predicate evaluates to\ntrue on a mutable reference to the value.

\n

In other words, replaces self with None if the predicate returns true.\nThis method operates similar to Option::take but conditional.

\n
Examples
\n
#![feature(option_take_if)]\n\nlet mut x = Some(42);\n\nlet prev = x.take_if(|v| if *v == 42 {\n    *v += 1;\n    false\n} else {\n    false\n});\nassert_eq!(x, Some(43));\nassert_eq!(prev, None);\n\nlet prev = x.take_if(|v| *v == 43);\nassert_eq!(x, None);\nassert_eq!(prev, Some(43));
\n
1.31.0 (const: unstable) · source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter,\nreturning the old value if present,\nleaving a Some in its place without deinitializing either one.

\n
Examples
\n
let mut x = Some(2);\nlet old = x.replace(5);\nassert_eq!(x, Some(5));\nassert_eq!(old, Some(2));\n\nlet mut x = None;\nlet old = x.replace(3);\nassert_eq!(x, Some(3));\nassert_eq!(old, None);
\n
1.46.0 · source

pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)>

Zips self with another Option.

\n

If self is Some(s) and other is Some(o), this method returns Some((s, o)).\nOtherwise, None is returned.

\n
Examples
\n
let x = Some(1);\nlet y = Some(\"hi\");\nlet z = None::<u8>;\n\nassert_eq!(x.zip(y), Some((1, \"hi\")));\nassert_eq!(x.zip(z), None);
\n
source

pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where\n F: FnOnce(T, U) -> R,

🔬This is a nightly-only experimental API. (option_zip)

Zips self and another Option with function f.

\n

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)).\nOtherwise, None is returned.

\n
Examples
\n
#![feature(option_zip)]\n\n#[derive(Debug, PartialEq)]\nstruct Point {\n    x: f64,\n    y: f64,\n}\n\nimpl Point {\n    fn new(x: f64, y: f64) -> Self {\n        Self { x, y }\n    }\n}\n\nlet x = Some(17.5);\nlet y = Some(42.7);\n\nassert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));\nassert_eq!(x.zip_with(None, Point::new), None);
\n
",0,"openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> PartialOrd for Option<T>
where\n T: PartialOrd,

source§

fn partial_cmp(&self, other: &Option<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <=\noperator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >=\noperator. Read more
","PartialOrd","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.37.0 · source§

impl<T, U> Product<Option<U>> for Option<T>
where\n T: Product<U>,

source§

fn product<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the product of all elements is returned.

\n
Examples
\n

This multiplies each number in a vector of strings,\nif a string could not be parsed the operation returns None:

\n\n
let nums = vec![\"5\", \"10\", \"1\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, Some(100));\nlet nums = vec![\"5\", \"10\", \"one\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, None);
\n
","Product>","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
source§

impl<T> FromResidual for Option<T>

source§

fn from_residual(residual: Option<Infallible>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

fn from_residual(_: Yeet<()>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual>","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
source§

impl<T> Try for Option<T>

§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

type Residual = Option<Infallible>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual\nas part of ? when short-circuiting. Read more
source§

fn from_output(output: <Option<T> as Try>::Output) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

fn branch(\n self\n) -> ControlFlow<<Option<T> as Try>::Residual, <Option<T> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value\n(because this returned ControlFlow::Continue)\nor propagate a value back to the caller\n(because this returned ControlFlow::Break). Read more
","Try","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Clone for Option<T>
where\n T: Clone,

source§

fn clone(&self) -> Option<T>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Option<T>)

Performs copy-assignment from source. Read more
","Clone","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<A, V> FromIterator<Option<A>> for Option<V>
where\n V: FromIterator<A>,

source§

fn from_iter<I>(iter: I) -> Option<V>
where\n I: IntoIterator<Item = Option<A>>,

Takes each element in the Iterator: if it is None,\nno further elements are taken, and the None is\nreturned. Should no None occur, a container of type\nV containing the values of each Option is returned.

\n
Examples
\n

Here is an example which increments every integer in a vector.\nWe use the checked variant of add that returns None when the\ncalculation would result in an overflow.

\n\n
let items = vec![0_u16, 1, 2];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_add(1))\n    .collect();\n\nassert_eq!(res, Some(vec![1, 2, 3]));
\n

As you can see, this will return the expected, valid items.

\n

Here is another example that tries to subtract one from another list\nof integers, this time checking for underflow:

\n\n
let items = vec![2_u16, 1, 0];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_sub(1))\n    .collect();\n\nassert_eq!(res, None);
\n

Since the last element is zero, it would underflow. Thus, the resulting\nvalue is None.

\n

Here is a variation on the previous example, showing that no\nfurther elements are taken from iter after the first None.

\n\n
let items = vec![3_u16, 2, 1, 10];\n\nlet mut shared = 0;\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| { shared += x; x.checked_sub(2) })\n    .collect();\n\nassert_eq!(res, None);\nassert_eq!(shared, 6);
\n

Since the third element caused an underflow, no further elements were taken,\nso the final value of shared is 6 (= 3 + 2 + 1), not 16.

\n
","FromIterator>","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> StructuralEq for Option<T>

","StructuralEq","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Eq for Option<T>
where\n T: Eq,

","Eq","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Hash for Option<T>
where\n T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where\n __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where\n H: Hasher,\n Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
","Hash","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Ord for Option<T>
where\n T: Ord,

source§

fn cmp(&self, other: &Option<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where\n Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
","Ord","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> PartialEq for Option<T>
where\n T: PartialEq,

source§

fn eq(&self, other: &Option<T>) -> bool

This method tests for self and other values to be equal, and is used\nby ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always\nsufficient, and should not be overridden without very good reason.
","PartialEq","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> IntoIterator for Option<T>

source§

fn into_iter(self) -> IntoIter<T>

Returns a consuming iterator over the possibly contained value.

\n
Examples
\n
let x = Some(\"string\");\nlet v: Vec<&str> = x.into_iter().collect();\nassert_eq!(v, [\"string\"]);\n\nlet x = None;\nlet v: Vec<&str> = x.into_iter().collect();\nassert!(v.is_empty());
\n
§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
","IntoIterator","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.37.0 · source§

impl<T, U> Sum<Option<U>> for Option<T>
where\n T: Sum<U>,

source§

fn sum<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the sum of all elements is returned.

\n
Examples
\n

This sums up the position of the character ‘a’ in a vector of strings,\nif a word did not have the character ‘a’ the operation returns None:

\n\n
let words = vec![\"have\", \"a\", \"great\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, Some(5));\nlet words = vec![\"have\", \"a\", \"good\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, None);
\n
","Sum>","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> StructuralPartialEq for Option<T>

","StructuralPartialEq","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Debug for Option<T>
where\n T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.12.0 · source§

impl<T> From<T> for Option<T>

source§

fn from(val: T) -> Option<T>

Moves val into a new Some.

\n
Examples
\n
let o: Option<u8> = Option::from(67);\n\nassert_eq!(Some(67), o);
\n
","From","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Copy for Option<T>
where\n T: Copy,

","Copy","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"],["
1.0.0 · source§

impl<T> Default for Option<T>

source§

fn default() -> Option<T>

Returns None.

\n
Examples
\n
let opt: Option<u32> = Option::default();\nassert!(opt.is_none());
\n
","Default","openssl_sys::openssl::handwritten::bio::bio_info_cb","openssl_sys::openssl::handwritten::pem::pem_password_cb","openssl_sys::openssl::handwritten::ssl::tls_session_ticket_ext_cb_fn","openssl_sys::openssl::handwritten::ssl::tls_session_secret_cb_fn","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_add_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_free_cb_ex","openssl_sys::openssl::handwritten::ssl::SSL_custom_ext_parse_cb_ex","openssl_sys::openssl::handwritten::ssl::GEN_SESSION_CB","openssl_sys::openssl::handwritten::ssl::SSL_CTX_keylog_cb_func","openssl_sys::openssl::handwritten::ssl::SSL_client_hello_cb_fn"]], "url":[["
source§

impl<T> Option<T>

1.0.0 (const: 1.48.0) · source

pub const fn is_some(&self) -> bool

Returns true if the option is a Some value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some(), true);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some(), false);
\n
1.70.0 · source

pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool

Returns true if the option is a Some and the value inside of it matches a predicate.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_some_and(|x| x > 1), true);\n\nlet x: Option<u32> = Some(0);\nassert_eq!(x.is_some_and(|x| x > 1), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_some_and(|x| x > 1), false);
\n
1.0.0 (const: 1.48.0) · source

pub const fn is_none(&self) -> bool

Returns true if the option is a None value.

\n
Examples
\n
let x: Option<u32> = Some(2);\nassert_eq!(x.is_none(), false);\n\nlet x: Option<u32> = None;\nassert_eq!(x.is_none(), true);
\n
1.0.0 (const: 1.48.0) · source

pub const fn as_ref(&self) -> Option<&T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Calculates the length of an Option<String> as an Option<usize>\nwithout moving the String. The map method takes the self argument by value,\nconsuming the original, so this technique uses as_ref to first take an Option to a\nreference to the value inside the original.

\n\n
let text: Option<String> = Some(\"Hello, world!\".to_string());\n// First, cast `Option<String>` to `Option<&String>` with `as_ref`,\n// then consume *that* with `map`, leaving `text` on the stack.\nlet text_length: Option<usize> = text.as_ref().map(|s| s.len());\nprintln!(\"still can print text: {text:?}\");
\n
1.0.0 (const: unstable) · source

pub fn as_mut(&mut self) -> Option<&mut T>

Converts from &mut Option<T> to Option<&mut T>.

\n
Examples
\n
let mut x = Some(2);\nmatch x.as_mut() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));
\n
1.33.0 (const: unstable) · source

pub fn as_pin_ref(self: Pin<&Option<T>>) -> Option<Pin<&T>>

Converts from Pin<&Option<T>> to Option<Pin<&T>>.

\n
1.33.0 (const: unstable) · source

pub fn as_pin_mut(self: Pin<&mut Option<T>>) -> Option<Pin<&mut T>>

Converts from Pin<&mut Option<T>> to Option<Pin<&mut T>>.

\n
1.75.0 · source

pub fn as_slice(&self) -> &[T]

Returns a slice of the contained value, if any. If this is None, an\nempty slice is returned. This can be useful to have a single type of\niterator over an Option or slice.

\n

Note: Should you have an Option<&T> and wish to get a slice of T,\nyou can unpack it via opt.map_or(&[], std::slice::from_ref).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_slice(), None.as_slice()],\n    [&[1234][..], &[][..]],\n);
\n

The inverse of this function is (discounting\nborrowing) [_]::first:

\n\n
for i in [Some(1234_u16), None] {\n    assert_eq!(i.as_ref(), i.as_slice().first());\n}
\n
1.75.0 · source

pub fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of the contained value, if any. If this is\nNone, an empty slice is returned. This can be useful to have a\nsingle type of iterator over an Option or slice.

\n

Note: Should you have an Option<&mut T> instead of a\n&mut Option<T>, which this method takes, you can obtain a mutable\nslice via opt.map_or(&mut [], std::slice::from_mut).

\n
Examples
\n
assert_eq!(\n    [Some(1234).as_mut_slice(), None.as_mut_slice()],\n    [&mut [1234][..], &mut [][..]],\n);
\n

The result is a mutable slice of zero or one items that points into\nour original Option:

\n\n
let mut x = Some(1234);\nx.as_mut_slice()[0] += 1;\nassert_eq!(x, Some(1235));
\n

The inverse of this method (discounting borrowing)\nis [_]::first_mut:

\n\n
assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
\n
1.0.0 (const: unstable) · source

pub fn expect(self, msg: &str) -> T

Returns the contained Some value, consuming the self value.

\n
Panics
\n

Panics if the value is a None with a custom panic message provided by\nmsg.

\n
Examples
\n
let x = Some(\"value\");\nassert_eq!(x.expect(\"fruits are healthy\"), \"value\");
\n\n
let x: Option<&str> = None;\nx.expect(\"fruits are healthy\"); // panics with `fruits are healthy`
\n
Recommended Message Style
\n

We recommend that expect messages are used to describe the reason you\nexpect the Option should be Some.

\n\n
let item = slice.get(0)\n    .expect(\"slice should not be empty\");
\n

Hint: If you’re having trouble remembering how to phrase expect\nerror messages remember to focus on the word “should” as in “env\nvariable should be set by blah” or “the given binary should be available\nand executable by the current user”.

\n

For more detail on expect message styles and the reasoning behind our\nrecommendation please refer to the section on “Common Message\nStyles” in the std::error module docs.

\n
1.0.0 (const: unstable) · source

pub fn unwrap(self) -> T

Returns the contained Some value, consuming the self value.

\n

Because this function may panic, its use is generally discouraged.\nInstead, prefer to use pattern matching and handle the None\ncase explicitly, or call unwrap_or, unwrap_or_else, or\nunwrap_or_default.

\n
Panics
\n

Panics if the self value equals None.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(x.unwrap(), \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(x.unwrap(), \"air\"); // fails
\n
1.0.0 · source

pub fn unwrap_or(self, default: T) -> T

Returns the contained Some value or a provided default.

\n

Arguments passed to unwrap_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use unwrap_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
assert_eq!(Some(\"car\").unwrap_or(\"bike\"), \"car\");\nassert_eq!(None.unwrap_or(\"bike\"), \"bike\");
\n
1.0.0 · source

pub fn unwrap_or_else<F>(self, f: F) -> T
where\n F: FnOnce() -> T,

Returns the contained Some value or computes it from a closure.

\n
Examples
\n
let k = 10;\nassert_eq!(Some(4).unwrap_or_else(|| 2 * k), 4);\nassert_eq!(None.unwrap_or_else(|| 2 * k), 20);
\n
1.0.0 · source

pub fn unwrap_or_default(self) -> T
where\n T: Default,

Returns the contained Some value or a default.

\n

Consumes the self argument then, if Some, returns the contained\nvalue, otherwise if None, returns the default value for that\ntype.

\n
Examples
\n
let x: Option<u32> = None;\nlet y: Option<u32> = Some(12);\n\nassert_eq!(x.unwrap_or_default(), 0);\nassert_eq!(y.unwrap_or_default(), 12);
\n
1.58.0 (const: unstable) · source

pub unsafe fn unwrap_unchecked(self) -> T

Returns the contained Some value, consuming the self value,\nwithout checking that the value is not None.

\n
Safety
\n

Calling this method on None is undefined behavior.

\n
Examples
\n
let x = Some(\"air\");\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\");
\n\n
let x: Option<&str> = None;\nassert_eq!(unsafe { x.unwrap_unchecked() }, \"air\"); // Undefined behavior!
\n
1.0.0 · source

pub fn map<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> U,

Maps an Option<T> to Option<U> by applying a function to a contained value (if Some) or returns None (if None).

\n
Examples
\n

Calculates the length of an Option<String> as an\nOption<usize>, consuming the original:

\n\n
let maybe_some_string = Some(String::from(\"Hello, World!\"));\n// `Option::map` takes self *by value*, consuming `maybe_some_string`\nlet maybe_some_len = maybe_some_string.map(|s| s.len());\nassert_eq!(maybe_some_len, Some(13));\n\nlet x: Option<&str> = None;\nassert_eq!(x.map(|s| s.len()), None);
\n
1.76.0 · source

pub fn inspect<F>(self, f: F) -> Option<T>
where\n F: FnOnce(&T),

Calls the provided closure with a reference to the contained value (if Some).

\n
Examples
\n
let v = vec![1, 2, 3, 4, 5];\n\n// prints \"got: 4\"\nlet x: Option<&usize> = v.get(3).inspect(|x| println!(\"got: {x}\"));\n\n// prints nothing\nlet x: Option<&usize> = v.get(5).inspect(|x| println!(\"got: {x}\"));
\n
1.0.0 · source

pub fn map_or<U, F>(self, default: U, f: F) -> U
where\n F: FnOnce(T) -> U,

Returns the provided default result (if none),\nor applies a function to the contained value (if any).

\n

Arguments passed to map_or are eagerly evaluated; if you are passing\nthe result of a function call, it is recommended to use map_or_else,\nwhich is lazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.map_or(42, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or(42, |v| v.len()), 42);
\n
1.0.0 · source

pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
where\n D: FnOnce() -> U,\n F: FnOnce(T) -> U,

Computes a default function result (if none), or\napplies a different function to the contained value (if any).

\n
Basic examples
\n
let k = 21;\n\nlet x = Some(\"foo\");\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 3);\n\nlet x: Option<&str> = None;\nassert_eq!(x.map_or_else(|| 2 * k, |v| v.len()), 42);
\n
Handling a Result-based fallback
\n

A somewhat common occurrence when dealing with optional values\nin combination with Result<T, E> is the case where one wants to invoke\na fallible fallback if the option is not present. This example\nparses a command line argument (if present), or the contents of a file to\nan integer. However, unlike accessing the command line argument, reading\nthe file is fallible, so it must be wrapped with Ok.

\n\n
let v: u64 = std::env::args()\n   .nth(1)\n   .map_or_else(|| std::fs::read_to_string(\"/etc/someconfig.conf\"), Ok)?\n   .parse()?;
\n
1.0.0 · source

pub fn ok_or<E>(self, err: E) -> Result<T, E>

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err).

\n

Arguments passed to ok_or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use ok_or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or(0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or(0), Err(0));
\n
1.0.0 · source

pub fn ok_or_else<E, F>(self, err: F) -> Result<T, E>
where\n F: FnOnce() -> E,

Transforms the Option<T> into a Result<T, E>, mapping Some(v) to\nOk(v) and None to Err(err()).

\n
Examples
\n
let x = Some(\"foo\");\nassert_eq!(x.ok_or_else(|| 0), Ok(\"foo\"));\n\nlet x: Option<&str> = None;\nassert_eq!(x.ok_or_else(|| 0), Err(0));
\n
1.40.0 · source

pub fn as_deref(&self) -> Option<&<T as Deref>::Target>
where\n T: Deref,

Converts from Option<T> (or &Option<T>) to Option<&T::Target>.

\n

Leaves the original Option in-place, creating a new one with a reference\nto the original one, additionally coercing the contents via Deref.

\n
Examples
\n
let x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref(), Some(\"hey\"));\n\nlet x: Option<String> = None;\nassert_eq!(x.as_deref(), None);
\n
1.40.0 · source

pub fn as_deref_mut(&mut self) -> Option<&mut <T as Deref>::Target>
where\n T: DerefMut,

Converts from Option<T> (or &mut Option<T>) to Option<&mut T::Target>.

\n

Leaves the original Option in-place, creating a new one containing a mutable reference to\nthe inner type’s Deref::Target type.

\n
Examples
\n
let mut x: Option<String> = Some(\"hey\".to_owned());\nassert_eq!(x.as_deref_mut().map(|x| {\n    x.make_ascii_uppercase();\n    x\n}), Some(\"HEY\".to_owned().as_mut_str()));
\n
1.0.0 (const: unstable) · source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the possibly contained value.

\n
Examples
\n
let x = Some(4);\nassert_eq!(x.iter().next(), Some(&4));\n\nlet x: Option<u32> = None;\nassert_eq!(x.iter().next(), None);
\n
1.0.0 · source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over the possibly contained value.

\n
Examples
\n
let mut x = Some(4);\nmatch x.iter_mut().next() {\n    Some(v) => *v = 42,\n    None => {},\n}\nassert_eq!(x, Some(42));\n\nlet mut x: Option<u32> = None;\nassert_eq!(x.iter_mut().next(), None);
\n
1.0.0 · source

pub fn and<U>(self, optb: Option<U>) -> Option<U>

Returns None if the option is None, otherwise returns optb.

\n

Arguments passed to and are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use and_then, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);\n\nlet x: Option<u32> = None;\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), None);\n\nlet x = Some(2);\nlet y = Some(\"foo\");\nassert_eq!(x.and(y), Some(\"foo\"));\n\nlet x: Option<u32> = None;\nlet y: Option<&str> = None;\nassert_eq!(x.and(y), None);
\n
1.0.0 · source

pub fn and_then<U, F>(self, f: F) -> Option<U>
where\n F: FnOnce(T) -> Option<U>,

Returns None if the option is None, otherwise calls f with the\nwrapped value and returns the result.

\n

Some languages call this operation flatmap.

\n
Examples
\n
fn sq_then_to_string(x: u32) -> Option<String> {\n    x.checked_mul(x).map(|sq| sq.to_string())\n}\n\nassert_eq!(Some(2).and_then(sq_then_to_string), Some(4.to_string()));\nassert_eq!(Some(1_000_000).and_then(sq_then_to_string), None); // overflowed!\nassert_eq!(None.and_then(sq_then_to_string), None);
\n

Often used to chain fallible operations that may return None.

\n\n
let arr_2d = [[\"A0\", \"A1\"], [\"B0\", \"B1\"]];\n\nlet item_0_1 = arr_2d.get(0).and_then(|row| row.get(1));\nassert_eq!(item_0_1, Some(&\"A1\"));\n\nlet item_2_0 = arr_2d.get(2).and_then(|row| row.get(0));\nassert_eq!(item_2_0, None);
\n
1.27.0 · source

pub fn filter<P>(self, predicate: P) -> Option<T>
where\n P: FnOnce(&T) -> bool,

Returns None if the option is None, otherwise calls predicate\nwith the wrapped value and returns:

\n
    \n
  • Some(t) if predicate returns true (where t is the wrapped\nvalue), and
  • \n
  • None if predicate returns false.
  • \n
\n

This function works similar to Iterator::filter(). You can imagine\nthe Option<T> being an iterator over one or zero elements. filter()\nlets you decide which elements to keep.

\n
Examples
\n
fn is_even(n: &i32) -> bool {\n    n % 2 == 0\n}\n\nassert_eq!(None.filter(is_even), None);\nassert_eq!(Some(3).filter(is_even), None);\nassert_eq!(Some(4).filter(is_even), Some(4));
\n
1.0.0 · source

pub fn or(self, optb: Option<T>) -> Option<T>

Returns the option if it contains a value, otherwise returns optb.

\n

Arguments passed to or are eagerly evaluated; if you are passing the\nresult of a function call, it is recommended to use or_else, which is\nlazily evaluated.

\n
Examples
\n
let x = Some(2);\nlet y = None;\nassert_eq!(x.or(y), Some(2));\n\nlet x = None;\nlet y = Some(100);\nassert_eq!(x.or(y), Some(100));\n\nlet x = Some(2);\nlet y = Some(100);\nassert_eq!(x.or(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = None;\nassert_eq!(x.or(y), None);
\n
1.0.0 · source

pub fn or_else<F>(self, f: F) -> Option<T>
where\n F: FnOnce() -> Option<T>,

Returns the option if it contains a value, otherwise calls f and\nreturns the result.

\n
Examples
\n
fn nobody() -> Option<&'static str> { None }\nfn vikings() -> Option<&'static str> { Some(\"vikings\") }\n\nassert_eq!(Some(\"barbarians\").or_else(vikings), Some(\"barbarians\"));\nassert_eq!(None.or_else(vikings), Some(\"vikings\"));\nassert_eq!(None.or_else(nobody), None);
\n
1.37.0 · source

pub fn xor(self, optb: Option<T>) -> Option<T>

Returns Some if exactly one of self, optb is Some, otherwise returns None.

\n
Examples
\n
let x = Some(2);\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), Some(2));\n\nlet x: Option<u32> = None;\nlet y = Some(2);\nassert_eq!(x.xor(y), Some(2));\n\nlet x = Some(2);\nlet y = Some(2);\nassert_eq!(x.xor(y), None);\n\nlet x: Option<u32> = None;\nlet y: Option<u32> = None;\nassert_eq!(x.xor(y), None);
\n
1.53.0 · source

pub fn insert(&mut self, value: T) -> &mut T

Inserts value into the option, then returns a mutable reference to it.

\n

If the option already contains a value, the old value is dropped.

\n

See also Option::get_or_insert, which doesn’t update the value if\nthe option already contains Some.

\n
Example
\n
let mut opt = None;\nlet val = opt.insert(1);\nassert_eq!(*val, 1);\nassert_eq!(opt.unwrap(), 1);\nlet val = opt.insert(2);\nassert_eq!(*val, 2);\n*val = 3;\nassert_eq!(opt.unwrap(), 3);
\n
1.20.0 · source

pub fn get_or_insert(&mut self, value: T) -> &mut T

Inserts value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n

See also Option::insert, which updates the value even if\nthe option already contains Some.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert(5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
source

pub fn get_or_insert_default(&mut self) -> &mut T
where\n T: Default,

🔬This is a nightly-only experimental API. (option_get_or_insert_default)

Inserts the default value into the option if it is None, then\nreturns a mutable reference to the contained value.

\n
Examples
\n
#![feature(option_get_or_insert_default)]\n\nlet mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_default();\n    assert_eq!(y, &0);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.20.0 · source

pub fn get_or_insert_with<F>(&mut self, f: F) -> &mut T
where\n F: FnOnce() -> T,

Inserts a value computed from f into the option if it is None,\nthen returns a mutable reference to the contained value.

\n
Examples
\n
let mut x = None;\n\n{\n    let y: &mut u32 = x.get_or_insert_with(|| 5);\n    assert_eq!(y, &5);\n\n    *y = 7;\n}\n\nassert_eq!(x, Some(7));
\n
1.0.0 (const: unstable) · source

pub fn take(&mut self) -> Option<T>

Takes the value out of the option, leaving a None in its place.

\n
Examples
\n
let mut x = Some(2);\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, Some(2));\n\nlet mut x: Option<u32> = None;\nlet y = x.take();\nassert_eq!(x, None);\nassert_eq!(y, None);
\n
source

pub fn take_if<P>(&mut self, predicate: P) -> Option<T>
where\n P: FnOnce(&mut T) -> bool,

🔬This is a nightly-only experimental API. (option_take_if)

Takes the value out of the option, but only if the predicate evaluates to\ntrue on a mutable reference to the value.

\n

In other words, replaces self with None if the predicate returns true.\nThis method operates similar to Option::take but conditional.

\n
Examples
\n
#![feature(option_take_if)]\n\nlet mut x = Some(42);\n\nlet prev = x.take_if(|v| if *v == 42 {\n    *v += 1;\n    false\n} else {\n    false\n});\nassert_eq!(x, Some(43));\nassert_eq!(prev, None);\n\nlet prev = x.take_if(|v| *v == 43);\nassert_eq!(x, None);\nassert_eq!(prev, Some(43));
\n
1.31.0 (const: unstable) · source

pub fn replace(&mut self, value: T) -> Option<T>

Replaces the actual value in the option by the value given in parameter,\nreturning the old value if present,\nleaving a Some in its place without deinitializing either one.

\n
Examples
\n
let mut x = Some(2);\nlet old = x.replace(5);\nassert_eq!(x, Some(5));\nassert_eq!(old, Some(2));\n\nlet mut x = None;\nlet old = x.replace(3);\nassert_eq!(x, Some(3));\nassert_eq!(old, None);
\n
1.46.0 · source

pub fn zip<U>(self, other: Option<U>) -> Option<(T, U)>

Zips self with another Option.

\n

If self is Some(s) and other is Some(o), this method returns Some((s, o)).\nOtherwise, None is returned.

\n
Examples
\n
let x = Some(1);\nlet y = Some(\"hi\");\nlet z = None::<u8>;\n\nassert_eq!(x.zip(y), Some((1, \"hi\")));\nassert_eq!(x.zip(z), None);
\n
source

pub fn zip_with<U, F, R>(self, other: Option<U>, f: F) -> Option<R>
where\n F: FnOnce(T, U) -> R,

🔬This is a nightly-only experimental API. (option_zip)

Zips self and another Option with function f.

\n

If self is Some(s) and other is Some(o), this method returns Some(f(s, o)).\nOtherwise, None is returned.

\n
Examples
\n
#![feature(option_zip)]\n\n#[derive(Debug, PartialEq)]\nstruct Point {\n    x: f64,\n    y: f64,\n}\n\nimpl Point {\n    fn new(x: f64, y: f64) -> Self {\n        Self { x, y }\n    }\n}\n\nlet x = Some(17.5);\nlet y = Some(42.7);\n\nassert_eq!(x.zip_with(y, Point::new), Some(Point { x: 17.5, y: 42.7 }));\nassert_eq!(x.zip_with(None, Point::new), None);
\n
",0,"url::EncodingOverride"],["
source§

impl<T> Option<&T>

1.35.0 (const: unstable) · source

pub fn copied(self) -> Option<T>
where\n T: Copy,

Maps an Option<&T> to an Option<T> by copying the contents of the\noption.

\n
Examples
\n
let x = 12;\nlet opt_x = Some(&x);\nassert_eq!(opt_x, Some(&12));\nlet copied = opt_x.copied();\nassert_eq!(copied, Some(12));
\n
1.0.0 · source

pub fn cloned(self) -> Option<T>
where\n T: Clone,

Maps an Option<&T> to an Option<T> by cloning the contents of the\noption.

\n
Examples
\n
let x = 12;\nlet opt_x = Some(&x);\nassert_eq!(opt_x, Some(&12));\nlet cloned = opt_x.cloned();\nassert_eq!(cloned, Some(12));
\n
",0,"url::EncodingOverride"],["
1.0.0 · source§

impl<T> PartialOrd for Option<T>
where\n T: PartialOrd,

source§

fn partial_cmp(&self, other: &Option<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <=\noperator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >=\noperator. Read more
","PartialOrd","url::EncodingOverride"],["
1.37.0 · source§

impl<T, U> Product<Option<U>> for Option<T>
where\n T: Product<U>,

source§

fn product<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the product of all elements is returned.

\n
Examples
\n

This multiplies each number in a vector of strings,\nif a string could not be parsed the operation returns None:

\n\n
let nums = vec![\"5\", \"10\", \"1\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, Some(100));\nlet nums = vec![\"5\", \"10\", \"one\", \"2\"];\nlet total: Option<usize> = nums.iter().map(|w| w.parse::<usize>().ok()).product();\nassert_eq!(total, None);
\n
","Product>","url::EncodingOverride"],["
source§

impl<T> FromResidual for Option<T>

source§

fn from_residual(residual: Option<Infallible>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual","url::EncodingOverride"],["
source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

fn from_residual(_: Yeet<()>) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from a compatible Residual type. Read more
","FromResidual>","url::EncodingOverride"],["
source§

impl<T> Try for Option<T>

§

type Output = T

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value produced by ? when not short-circuiting.
§

type Residual = Option<Infallible>

🔬This is a nightly-only experimental API. (try_trait_v2)
The type of the value passed to FromResidual::from_residual\nas part of ? when short-circuiting. Read more
source§

fn from_output(output: <Option<T> as Try>::Output) -> Option<T>

🔬This is a nightly-only experimental API. (try_trait_v2)
Constructs the type from its Output type. Read more
source§

fn branch(\n self\n) -> ControlFlow<<Option<T> as Try>::Residual, <Option<T> as Try>::Output>

🔬This is a nightly-only experimental API. (try_trait_v2)
Used in ? to decide whether the operator should produce a value\n(because this returned ControlFlow::Continue)\nor propagate a value back to the caller\n(because this returned ControlFlow::Break). Read more
","Try","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Clone for Option<T>
where\n T: Clone,

source§

fn clone(&self) -> Option<T>

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Option<T>)

Performs copy-assignment from source. Read more
","Clone","url::EncodingOverride"],["
1.0.0 · source§

impl<A, V> FromIterator<Option<A>> for Option<V>
where\n V: FromIterator<A>,

source§

fn from_iter<I>(iter: I) -> Option<V>
where\n I: IntoIterator<Item = Option<A>>,

Takes each element in the Iterator: if it is None,\nno further elements are taken, and the None is\nreturned. Should no None occur, a container of type\nV containing the values of each Option is returned.

\n
Examples
\n

Here is an example which increments every integer in a vector.\nWe use the checked variant of add that returns None when the\ncalculation would result in an overflow.

\n\n
let items = vec![0_u16, 1, 2];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_add(1))\n    .collect();\n\nassert_eq!(res, Some(vec![1, 2, 3]));
\n

As you can see, this will return the expected, valid items.

\n

Here is another example that tries to subtract one from another list\nof integers, this time checking for underflow:

\n\n
let items = vec![2_u16, 1, 0];\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| x.checked_sub(1))\n    .collect();\n\nassert_eq!(res, None);
\n

Since the last element is zero, it would underflow. Thus, the resulting\nvalue is None.

\n

Here is a variation on the previous example, showing that no\nfurther elements are taken from iter after the first None.

\n\n
let items = vec![3_u16, 2, 1, 10];\n\nlet mut shared = 0;\n\nlet res: Option<Vec<u16>> = items\n    .iter()\n    .map(|x| { shared += x; x.checked_sub(2) })\n    .collect();\n\nassert_eq!(res, None);\nassert_eq!(shared, 6);
\n

Since the third element caused an underflow, no further elements were taken,\nso the final value of shared is 6 (= 3 + 2 + 1), not 16.

\n
","FromIterator>","url::EncodingOverride"],["
1.0.0 · source§

impl<T> StructuralEq for Option<T>

","StructuralEq","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Eq for Option<T>
where\n T: Eq,

","Eq","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Hash for Option<T>
where\n T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where\n __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where\n H: Hasher,\n Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
","Hash","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Ord for Option<T>
where\n T: Ord,

source§

fn cmp(&self, other: &Option<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where\n Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where\n Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
","Ord","url::EncodingOverride"],["
1.0.0 · source§

impl<T> PartialEq for Option<T>
where\n T: PartialEq,

source§

fn eq(&self, other: &Option<T>) -> bool

This method tests for self and other values to be equal, and is used\nby ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always\nsufficient, and should not be overridden without very good reason.
","PartialEq","url::EncodingOverride"],["
1.0.0 · source§

impl<T> IntoIterator for Option<T>

source§

fn into_iter(self) -> IntoIter<T>

Returns a consuming iterator over the possibly contained value.

\n
Examples
\n
let x = Some(\"string\");\nlet v: Vec<&str> = x.into_iter().collect();\nassert_eq!(v, [\"string\"]);\n\nlet x = None;\nlet v: Vec<&str> = x.into_iter().collect();\nassert!(v.is_empty());
\n
§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
","IntoIterator","url::EncodingOverride"],["
1.37.0 · source§

impl<T, U> Sum<Option<U>> for Option<T>
where\n T: Sum<U>,

source§

fn sum<I>(iter: I) -> Option<T>
where\n I: Iterator<Item = Option<U>>,

Takes each element in the Iterator: if it is a None, no further\nelements are taken, and the None is returned. Should no None\noccur, the sum of all elements is returned.

\n
Examples
\n

This sums up the position of the character ‘a’ in a vector of strings,\nif a word did not have the character ‘a’ the operation returns None:

\n\n
let words = vec![\"have\", \"a\", \"great\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, Some(5));\nlet words = vec![\"have\", \"a\", \"good\", \"day\"];\nlet total: Option<usize> = words.iter().map(|w| w.find('a')).sum();\nassert_eq!(total, None);
\n
","Sum>","url::EncodingOverride"],["
1.0.0 · source§

impl<T> StructuralPartialEq for Option<T>

","StructuralPartialEq","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Debug for Option<T>
where\n T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
","Debug","url::EncodingOverride"],["
1.30.0 · source§

impl<'a, T> From<&'a Option<T>> for Option<&'a T>

source§

fn from(o: &'a Option<T>) -> Option<&'a T>

Converts from &Option<T> to Option<&T>.

\n
Examples
\n

Converts an Option<String> into an Option<usize>, preserving\nthe original. The map method takes the self argument by value, consuming the original,\nso this technique uses from to first take an Option to a reference\nto the value inside the original.

\n\n
let s: Option<String> = Some(String::from(\"Hello, Rustaceans!\"));\nlet o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len());\n\nprintln!(\"Can still print s: {s:?}\");\n\nassert_eq!(o, Some(18));
\n
","From<&'a Option>","url::EncodingOverride"],["
1.12.0 · source§

impl<T> From<T> for Option<T>

source§

fn from(val: T) -> Option<T>

Moves val into a new Some.

\n
Examples
\n
let o: Option<u8> = Option::from(67);\n\nassert_eq!(Some(67), o);
\n
","From","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Copy for Option<T>
where\n T: Copy,

","Copy","url::EncodingOverride"],["
1.0.0 · source§

impl<T> Default for Option<T>

source§

fn default() -> Option<T>

Returns None.

\n
Examples
\n
let opt: Option<u32> = Option::default();\nassert!(opt.is_none());
\n
","Default","url::EncodingOverride"]] };if (window.register_type_impls) {window.register_type_impls(type_impls);} else {window.pending_type_impls = type_impls;}})()