Trait diesel::result::OptionalExtension
[−]
[src]
pub trait OptionalExtension<T> {
fn optional(self) -> Result<Option<T>, Error>;
}See the method documentation.
Required Methods
fn optional(self) -> Result<Option<T>, Error>
Converts a QueryResult<T> into a QueryResult<Option<T>>.
By default, Diesel treats 0 rows being returned from a query that is expected to return 1
row as an error (e.g. the return value of get_result or first). This method will
handle that error, and give you back an Option<T> instead.
Example
use diesel::result::{QueryResult, Error}; use diesel::OptionalExtension; let result: QueryResult<i32> = Ok(1); assert_eq!(Ok(Some(1)), result.optional()); let result: QueryResult<i32> = Err(Error::NotFound); assert_eq!(Ok(None), result.optional());
Implementors
impl<T> OptionalExtension<T> for QueryResult<T>